Skip to content

Commit 3f0c95f

Browse files
authored
[COM-38695] Port subscription-price formatter from template-compiler (#29)
* Port subscription-price formatter from template-compiler Port template, formatter, unimplemented commerce utils, and test cases from template-compiler * Add maximumFractionDigits to NumberFormatter Need to make sure that there are always 2 fraction digits after formatting, so we need both min and max set
1 parent e121d92 commit 3f0c95f

14 files changed

+1524
-10
lines changed

__tests__/plugins/formatters.commerce.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,31 @@ loader.paths('f-variants-select-%N.html').forEach((path) => {
142142
loader.paths('f-variants-select-subscription.html').forEach((path) => {
143143
test(`variants select subscription - ${path}`, () => loader.execute(path));
144144
});
145+
146+
loader.paths('f-subscription-price-multiple-variants-and-multiple-pricing-options.html').forEach((path) => {
147+
test(`subscription price multiple variants and multiple pricing options - ${path}`, () => loader.execute(path));
148+
});
149+
150+
loader.paths('f-subscription-price-multiple-variants-from-price.html').forEach((path) => {
151+
test(`subscription price multiple variants from price - ${path}`, () => loader.execute(path));
152+
});
153+
154+
loader.paths('f-subscription-price-on-sale-variants-pricing-options.html').forEach((path) => {
155+
test(`subscription price on sale variants pricing options - ${path}`, () => loader.execute(path));
156+
});
157+
158+
loader.paths('f-subscription-price-one-on-sale-pricing-option.html').forEach((path) => {
159+
test(`subscription price one on sale pricing option - ${path}`, () => loader.execute(path));
160+
});
161+
162+
loader.paths('f-subscription-price-one-pricing-option.html').forEach((path) => {
163+
test(`subscription price one pricing option - ${path}`, () => loader.execute(path));
164+
});
165+
166+
loader.paths('f-subscription-price-variants-with-same-pricing.html').forEach((path) => {
167+
test(`subscription price variants with same pricing - ${path}`, () => loader.execute(path));
168+
});
169+
170+
loader.paths('f-subscription-price-no-pricing-options.html').forEach((path) => {
171+
test(`subscription price no pricing options - ${path}`, () => loader.execute(path));
172+
});
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
:JSON
2+
{
3+
"structuredContent": {
4+
"productType": 1,
5+
"variants": [{
6+
"price": 1000,
7+
"priceMoney": {
8+
"value": "10"
9+
},
10+
"onSale": false,
11+
"pricingOptions": [{
12+
"price" : "900",
13+
"priceMoney": {
14+
"value": "9",
15+
"currency": "USD"
16+
},
17+
"salePrice" : 0,
18+
"salePriceMoney": {
19+
"value": "0",
20+
"currency": "USD"
21+
},
22+
"percentageDiscount" : 0.1,
23+
"onSale" : false,
24+
"productSubscriptionOptionId" : "c0733e4d-8b1b-400e-a3fc-f2f8fdc21e7f",
25+
"subscriptionPlan" : {
26+
"billingPeriod" : {
27+
"value" : 3,
28+
"unit" : "MONTH"
29+
},
30+
"planVersionId" : "3d2d5ea7-a571-4709-b5bc-59223c5a8fbd",
31+
"numBillingCycles" : 2
32+
}
33+
},
34+
{
35+
"price" : "0",
36+
"priceMoney": {
37+
"value": "0",
38+
"currency": "USD"
39+
},
40+
"salePrice" : 0,
41+
"salePriceMoney": {
42+
"value": "0",
43+
"currency": "USD"
44+
},
45+
"percentageDiscount" : 1,
46+
"onSale" : false,
47+
"productSubscriptionOptionId" : "c0733e4d-8b1b-400e-a3fc-f2f8fdc21e7f",
48+
"subscriptionPlan" : {
49+
"billingPeriod" : {
50+
"value" : 3,
51+
"unit" : "MONTH"
52+
},
53+
"planVersionId" : "3d2d5ea7-a571-4709-b5bc-59223c5a8fbd",
54+
"numBillingCycles" : 2
55+
}
56+
}]
57+
},
58+
{
59+
"price": 2000,
60+
"priceMoney": {
61+
"value": "20"
62+
},
63+
"onSale": false,
64+
"pricingOptions": [{
65+
"price" : "1800",
66+
"priceMoney": {
67+
"value": "18",
68+
"currency": "USD"
69+
},
70+
"salePrice" : 0,
71+
"salePriceMoney": {
72+
"value": 0,
73+
"currency": "USD"
74+
},
75+
"percentageDiscount" : 0.2,
76+
"onSale" : false,
77+
"productSubscriptionOptionId" : "c56446e4d-8b1b-400e-a3fc-f2f8fdc21e7f",
78+
"subscriptionPlan" : {
79+
"billingPeriod" : {
80+
"value" : 3,
81+
"unit" : "MONTH"
82+
},
83+
"planVersionId" : "3d2d5ea7-a571-4709-b5bc-59223c5a8fbd",
84+
"numBillingCycles" : 2
85+
}
86+
}]
87+
},
88+
{
89+
"price": 3000,
90+
"priceMoney": {
91+
"value": "30"
92+
},
93+
"onSale": false,
94+
"pricingOptions": [{
95+
"price" : "2400",
96+
"priceMoney": {
97+
"value": "24",
98+
"currency": "USD"
99+
},
100+
"salePrice" : 0,
101+
"salePriceMoney": {
102+
"value": 0,
103+
"currency": "USD"
104+
},
105+
"percentageDiscount" : 0.2,
106+
"onSale" : false,
107+
"productSubscriptionOptionId" : "c9656e4d-8b1b-400e-a3fc-f2f8fdc21e7f",
108+
"subscriptionPlan" : {
109+
"billingPeriod" : {
110+
"value" : 3,
111+
"unit" : "MONTH"
112+
},
113+
"planVersionId" : "3d2d5ea7-a571-4709-b5bc-59223c5a8fbd",
114+
"numBillingCycles" : 2
115+
}
116+
}]
117+
}]
118+
}
119+
}
120+
121+
:TEMPLATE
122+
{@|subscription-price}
123+
124+
:OUTPUT
125+
<div class="subscription-price">
126+
from <span class="sqs-money-native">9.00</span>
127+
128+
</div>

0 commit comments

Comments
 (0)