@gem-sdk/components 12.0.0-dev.48 → 12.0.0-dev.49
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js");const useProductPriceBreakdown=()=>{let e=core.useProductOfferDiscount(),r=core.useCurrentVariant(),o=core.useProduct(),c=core.useProductStore(e=>e.selectedSellingPlan),{quantity:i}=core.useQuantity(),
|
|
1
|
+
"use strict";var React=require("react"),core=require("@gem-sdk/core"),getPrice=require("../helpers/product-price-breakdown/getPrice.js");const useProductPriceBreakdown=()=>{let e=core.useProductOfferDiscount(),r=core.useCurrentVariant(),o=core.useProduct(),c=core.useProductStore(e=>e.selectedSellingPlan),{quantity:i}=core.useQuantity(),t=React.useMemo(()=>{if(!c)return null;let e=r?.sellingPlanGroups??o?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===c);if(e)return e}return null},[r,o,c]),n=core.convertDecimalToNumber(r?.price)??0,s=React.useMemo(()=>!t||n<=0?0:getPrice.calculateSellingPlanDiscount({variantPrice:n,pricingPolicies:t.pricingPolicies}),[t,n]),u=Math.max(0,parseFloat(core.shopifyPriceRounding(n-s,2))),a=Math.max(0,parseFloat(core.shopifyPriceRounding(u*(i||1),2))),l=core.useFormatMoney(a,!1),P=e*(i||1),d=parseFloat(core.shopifyPriceRounding(P,2)),p=core.useFormatMoney(d,!1),g=core.shopifyPriceRounding(d,2),f=parseFloat(core.shopifyPriceRounding(a-parseFloat(g),2)),m=core.useFormatMoney(f>0?f:0,!1);return{price:n,sellingPlanDiscountPerUnit:s,priceAfterSellingPlanDiscount:u,subTotal:a,subTotalMoneyFormatted:l,offerDiscountTotal:P,discountWithQuantity:d,discountMoneyFormatted:p,totalMoneyFormatted:m}};exports.useProductPriceBreakdown=useProductPriceBreakdown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useMemo as e}from"react";import{useProductOfferDiscount as r,useCurrentVariant as l,useProduct as i,useProductStore as
|
|
1
|
+
import{useMemo as e}from"react";import{useProductOfferDiscount as r,useCurrentVariant as l,useProduct as i,useProductStore as t,useQuantity as a,convertDecimalToNumber as o,shopifyPriceRounding as n,useFormatMoney as s}from"@gem-sdk/core";import{calculateSellingPlanDiscount as p}from"../helpers/product-price-breakdown/getPrice.js";let useProductPriceBreakdown=()=>{let c=r(),u=l(),P=i(),d=t(e=>e.selectedSellingPlan),{quantity:f}=a(),g=e(()=>{if(!d)return null;let e=u?.sellingPlanGroups??P?.sellingPlanGroups??[];for(let r of e)if(r?.sellingPlans){let e=r.sellingPlans.find(e=>e?.baseID===d);if(e)return e}return null},[u,P,d]),m=o(u?.price)??0,F=e(()=>!g||m<=0?0:p({variantPrice:m,pricingPolicies:g.pricingPolicies}),[g,m]),k=Math.max(0,parseFloat(n(m-F,2))),h=Math.max(0,parseFloat(n(k*(f||1),2))),w=s(h,!1),x=c*(f||1),b=parseFloat(n(x,2)),B=s(b,!1),G=n(b,2),M=parseFloat(n(h-parseFloat(G),2)),j=s(M>0?M:0,!1);return{price:m,sellingPlanDiscountPerUnit:F,priceAfterSellingPlanDiscount:k,subTotal:h,subTotalMoneyFormatted:w,offerDiscountTotal:x,discountWithQuantity:b,discountMoneyFormatted:B,totalMoneyFormatted:j}};export{useProductPriceBreakdown};
|