Skip to content

Commit 03bfcd2

Browse files
authored
[COM-32536]: Variant pricing bug fixes (#53)
* fix bugs * add test
1 parent def58c1 commit 03bfcd2

File tree

5 files changed

+193
-3
lines changed

5 files changed

+193
-3
lines changed

core/src/main/java/com/squarespace/template/plugins/platform/CommerceFormatters.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,14 @@ public void apply(Context ctx, Arguments args, Variables variables) throws CodeE
493493
JsonNode pricingOptions = CommerceUtils.getPricingOptionsAmongLowestVariant(node);
494494

495495
if (pricingOptions != null && pricingOptions.size() > 0) {
496-
if (CommerceUtils.hasVariants(node)) {
496+
if (CommerceUtils.hasVariedPrices(node)) {
497497
// This will return either salePriceMoney or priceMoney depending on whether the onSale is true or false.
498498
// That's because this block here is the from {price} so the from price needs to be the lowest possible price
499499
// taking into if a variant is onSale.
500500
JsonNode subscriptionFromPricingNode = CommerceUtils.getSubscriptionMoneyFromFirstPricingOptions(pricingOptions);
501501

502502
subscriptionResults.put("fromText", StringUtils.defaultIfEmpty(
503-
ctx.resolve(Constants.PRODUCT_PRICE_FROM_TEXT_KEY).asText(), "from {price}"));
503+
ctx.resolve(Constants.PRODUCT_PRICE_FROM_TEXT_KEY).asText(), "from {fromPrice}"));
504504
subscriptionResults.put("formattedFromPrice", CommerceUtils.getMoneyString(subscriptionFromPricingNode, ctx));
505505
}
506506

core/src/main/resources/com/squarespace/template/plugins/platform/subscription-price.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
normal-price if both from-price and sale-price doesn't exists.
88
##}
99
<div class="subscription-price">
10-
{.if formattedFromPrice}{fromText|message price:formattedFromPrice}
10+
{.if formattedFromPrice}{fromText|message fromPrice:formattedFromPrice}
1111
{.or}{.if formattedSubscriptionSalePrice}<span class="visually-hidden v6-visually-hidden">{.if @salePriceText}{@salePriceText|htmltag}{.or}Sale Price:{.end}</span>{formattedSubscriptionSalePriceText|message price:formattedSubscriptionSalePrice}{.space}<span class="visually-hidden v6-visually-hidden">{.if @originalPriceText}{@originalPriceText|htmltag}{.or}Original Price:{.end}</span><span class="original-price">{formattedNormalSubscriptionPriceText|message price:formattedNormalSubscriptionPrice}</span>
1212
{.or}{.if formattedNormalSubscriptionPrice}{formattedNormalSubscriptionPriceText|message price:formattedNormalSubscriptionPrice}{.end}{.end}{.end}
1313
</div>

core/src/test/java/com/squarespace/template/plugins/platform/CommerceFormattersTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public void testSubscriptionPrice() {
248248
"f-subscription-price-on-sale-variants-pricing-options.html",
249249
"f-subscription-price-one-on-sale-pricing-option.html",
250250
"f-subscription-price-one-pricing-option.html",
251+
"f-subscription-price-variants-with-same-pricing.html",
251252
"f-subscription-price-no-pricing-options.html"
252253
);
253254
}

core/src/test/resources/com/squarespace/template/plugins/platform/f-subscription-price-multiple-variants-and-multiple-pricing-options.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"structuredContent": {
44
"productType": 1,
55
"variants": [{
6+
"price": 1000,
67
"priceMoney": {
78
"value": "10"
89
},
@@ -55,6 +56,7 @@
5556
}]
5657
},
5758
{
59+
"price": 2000,
5860
"priceMoney": {
5961
"value": "20"
6062
},
@@ -84,6 +86,7 @@
8486
}]
8587
},
8688
{
89+
"price": 3000,
8790
"priceMoney": {
8891
"value": "30"
8992
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
:JSON
2+
{
3+
"structuredContent": {
4+
"productType": 1,
5+
"variants" : [ {
6+
"attributes" : {
7+
"Color" : "Navy"
8+
},
9+
"optionValues" : [ {
10+
"optionName" : "Color",
11+
"value" : "Navy"
12+
} ],
13+
"id" : "2c15e571-96a3-416d-bcbf-b586fb6d86a5",
14+
"sku" : "SQ4623793",
15+
"price" : 2000,
16+
"salePrice" : 0,
17+
"priceMoney" : {
18+
"currency" : "USD",
19+
"value" : "20.00"
20+
},
21+
"salePriceMoney" : {
22+
"currency" : "USD",
23+
"value" : "0.00"
24+
},
25+
"onSale" : false,
26+
"unlimited" : false,
27+
"qtyInStock" : 1,
28+
"width" : 0.0,
29+
"height" : 0.0,
30+
"weight" : 0.0,
31+
"imageIds" : [ ],
32+
"images" : [ ],
33+
"pricingOptions" : [ {
34+
"price" : 1800,
35+
"salePrice" : 0,
36+
"percentageDiscount" : 0.1,
37+
"priceMoney" : {
38+
"currency" : "USD",
39+
"value" : "18.00"
40+
},
41+
"salePriceMoney" : {
42+
"currency" : "USD",
43+
"value" : "0.00"
44+
},
45+
"onSale" : false,
46+
"productSubscriptionOptionId" : "f6949b20-8d71-447a-a5ee-8c07132e70b4",
47+
"subscriptionPlan" : {
48+
"billingPeriod" : {
49+
"value" : 1,
50+
"unit" : "WEEK"
51+
},
52+
"planVersionId" : "30066d47-c460-4ee2-b53e-3d4ec2c008a7",
53+
"numBillingCycles" : 5
54+
}
55+
} ],
56+
"len" : 0.0
57+
}, {
58+
"attributes" : {
59+
"Color" : "Red"
60+
},
61+
"optionValues" : [ {
62+
"optionName" : "Color",
63+
"value" : "Red"
64+
} ],
65+
"id" : "30303da6-ae10-4cc4-8639-ebdf1e86e3b8",
66+
"sku" : "SQ0235523",
67+
"price" : 2000,
68+
"salePrice" : 0,
69+
"priceMoney" : {
70+
"currency" : "USD",
71+
"value" : "20.00"
72+
},
73+
"salePriceMoney" : {
74+
"currency" : "USD",
75+
"value" : "0.00"
76+
},
77+
"onSale" : false,
78+
"unlimited" : false,
79+
"qtyInStock" : 1,
80+
"width" : 0.0,
81+
"height" : 0.0,
82+
"weight" : 0.0,
83+
"imageIds" : [ ],
84+
"images" : [ ],
85+
"pricingOptions" : [ {
86+
"price" : 1800,
87+
"salePrice" : 0,
88+
"percentageDiscount" : 0.1,
89+
"priceMoney" : {
90+
"currency" : "USD",
91+
"value" : "18.00"
92+
},
93+
"salePriceMoney" : {
94+
"currency" : "USD",
95+
"value" : "0.00"
96+
},
97+
"onSale" : false,
98+
"productSubscriptionOptionId" : "f6949b20-8d71-447a-a5ee-8c07132e70b4",
99+
"subscriptionPlan" : {
100+
"billingPeriod" : {
101+
"value" : 1,
102+
"unit" : "WEEK"
103+
},
104+
"planVersionId" : "30066d47-c460-4ee2-b53e-3d4ec2c008a7",
105+
"numBillingCycles" : 5
106+
}
107+
} ],
108+
"len" : 0.0
109+
}, {
110+
"attributes" : {
111+
"Color" : "Green"
112+
},
113+
"optionValues" : [ {
114+
"optionName" : "Color",
115+
"value" : "Green"
116+
} ],
117+
"id" : "5ac0518a-38f3-4910-ae11-1e90a87c46e5",
118+
"sku" : "SQ8531651",
119+
"price" : 2000,
120+
"salePrice" : 0,
121+
"priceMoney" : {
122+
"currency" : "USD",
123+
"value" : "20.00"
124+
},
125+
"salePriceMoney" : {
126+
"currency" : "USD",
127+
"value" : "0.00"
128+
},
129+
"onSale" : false,
130+
"unlimited" : false,
131+
"qtyInStock" : 1,
132+
"width" : 0.0,
133+
"height" : 0.0,
134+
"weight" : 0.0,
135+
"imageIds" : [ ],
136+
"images" : [ ],
137+
"pricingOptions" : [ {
138+
"price" : 1800,
139+
"salePrice" : 0,
140+
"percentageDiscount" : 0.1,
141+
"priceMoney" : {
142+
"currency" : "USD",
143+
"value" : "18.00"
144+
},
145+
"salePriceMoney" : {
146+
"currency" : "USD",
147+
"value" : "0.00"
148+
},
149+
"onSale" : false,
150+
"productSubscriptionOptionId" : "f6949b20-8d71-447a-a5ee-8c07132e70b4",
151+
"subscriptionPlan" : {
152+
"billingPeriod" : {
153+
"value" : 1,
154+
"unit" : "WEEK"
155+
},
156+
"planVersionId" : "30066d47-c460-4ee2-b53e-3d4ec2c008a7",
157+
"numBillingCycles" : 5
158+
}
159+
} ],
160+
"len" : 0.0
161+
} ],
162+
"variantOptionOrdering" : [ "Color" ],
163+
"isSubscribable" : false,
164+
"fulfilledExternally" : false,
165+
"productSubscriptionOptions" : [ {
166+
"id" : "f6949b20-8d71-447a-a5ee-8c07132e70b4",
167+
"percentageDiscount" : 0.1,
168+
"subscriptionPlan" : {
169+
"billingPeriod" : {
170+
"value" : 1,
171+
"unit" : "WEEK"
172+
},
173+
"planVersionId" : "30066d47-c460-4ee2-b53e-3d4ec2c008a7",
174+
"numBillingCycles" : 5
175+
}
176+
}]
177+
}
178+
}
179+
180+
:TEMPLATE
181+
{@|subscription-price}
182+
183+
:OUTPUT
184+
<div class="subscription-price">
185+
<span class="sqs-money-native">18.00</span>
186+
</div>

0 commit comments

Comments
 (0)