@ordergroove/offers 2.30.1 → 2.30.2-alpha-PR-715-3.3

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.1",
3
+ "version": "2.30.2-alpha-PR-715-3.3+1cc1ca11",
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": "80a8e7736af03c41fc30fc1fe9294cfd947b2482"
50
+ "gitHead": "1cc1ca119c0d7aaaf8552855075f89a62dbd3049"
51
51
  }
@@ -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) => {
@@ -81,8 +81,8 @@ export const addPrepaidPriceAndSavings = (
81
81
  payAsYouGoAdjustment && payAsYouGoAdjustment.value_type === 'percentage' ? payAsYouGoAdjustment.value : null;
82
82
 
83
83
  productPlan['regularPrepaidPrice'] = money(allocation.price);
84
- productPlan['prepaidSavingsPerShipment'] = money(prepaidSaving);
85
- productPlan['prepaidSavingsTotal'] = money(prepaidSaving * prepaidShipmentsPerBilling);
84
+ productPlan['prepaidSavingsPerShipment'] = money(Math.round(prepaidSaving));
85
+ productPlan['prepaidSavingsTotal'] = money(Math.round(prepaidSaving * prepaidShipmentsPerBilling));
86
86
 
87
87
  if (payAsYouGoPercentage && prepaidPercentageSavings) {
88
88
  productPlan['prepaidExtraSavingsPercentage'] = percentage(prepaidPercentageSavings - payAsYouGoPercentage);