@ordergroove/offers 2.30.1 → 2.30.2-alpha-PR-715-2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.30.
|
|
3
|
+
"version": "2.30.2-alpha-PR-715-2.2+d5714495",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@ordergroove/offers-templates": "^0.5.1"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "d571449557e4e91e131a22624335e4d583484a5b"
|
|
51
51
|
}
|
package/src/components/Price.js
CHANGED
|
@@ -13,6 +13,7 @@ export class Price extends withProduct(TemplateElement) {
|
|
|
13
13
|
regular: { type: Boolean, reflect: true },
|
|
14
14
|
subscription: { type: Boolean, reflect: true },
|
|
15
15
|
discount: { type: Boolean, reflect: true },
|
|
16
|
+
payAsYouGo: { type: Boolean, reflect: true, attribute: 'pay-as-you-go' },
|
|
16
17
|
frequency: { type: Object },
|
|
17
18
|
productPlans: { type: Object }
|
|
18
19
|
};
|
|
@@ -22,6 +23,13 @@ export class Price extends withProduct(TemplateElement) {
|
|
|
22
23
|
const realProductId = safeProductId(this.product);
|
|
23
24
|
const frequency = this.frequency || this.configDefaultFrequency || this.offer?.defaultFrequency;
|
|
24
25
|
const plans = this.productPlans[realProductId] || [];
|
|
26
|
+
|
|
27
|
+
if (this.payAsYouGo) {
|
|
28
|
+
const payAsYouGoPlan = plans.find(plan => plan.prepaidShipments === null);
|
|
29
|
+
if (!payAsYouGoPlan) return '';
|
|
30
|
+
return payAsYouGoPlan.subscriptionPrice;
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
const currentPlan = plans.find(plan => plan.frequency === frequency);
|
|
26
34
|
if (!currentPlan) return '';
|
|
27
35
|
const { regularPrice, discountRate, subscriptionPrice } = currentPlan;
|
|
@@ -35,7 +35,7 @@ export const getAllocationSubscriptionPrice = (allocation: ShopifySellingPlanAll
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const getPrepaidPercentage = (allocation: ShopifySellingPlanAllocationsEntity, pricePerShipment: number) => {
|
|
38
|
-
return ((allocation.compare_at_price - pricePerShipment) * 100) / allocation.compare_at_price;
|
|
38
|
+
return Math.round(((allocation.compare_at_price - pricePerShipment) * 100) / allocation.compare_at_price);
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export const getAllocationDiscountRate = (allocation: ShopifySellingPlanAllocationsEntity) => {
|
|
@@ -73,8 +73,8 @@ export const addPrepaidPriceAndSavings = (
|
|
|
73
73
|
payAsYouGoPlan: ShopifySellingPlansEntity
|
|
74
74
|
) => {
|
|
75
75
|
const prepaidShipmentsPerBilling = getPrepaidShipmentsNumberFromOptions(allocation.selling_plan?.options);
|
|
76
|
-
const pricePerShipment = allocation.price / prepaidShipmentsPerBilling;
|
|
77
|
-
const prepaidSaving = allocation.compare_at_price - pricePerShipment;
|
|
76
|
+
const pricePerShipment = Math.round(allocation.price / prepaidShipmentsPerBilling);
|
|
77
|
+
const prepaidSaving = Math.round(allocation.compare_at_price - pricePerShipment);
|
|
78
78
|
const prepaidPercentageSavings = getPrepaidPercentage(allocation, pricePerShipment);
|
|
79
79
|
const payAsYouGoAdjustment = payAsYouGoPlan?.price_adjustments?.[0];
|
|
80
80
|
const payAsYouGoPercentage =
|