UNPKG

@kadconsulting/dry

Version:
44 lines 1.85 kB
// import { MerchandiseData, PromotionalPricingAttributes } from '../types/main'; const getPrice = ({ product }) => { // const getPrice = ({ product }: { product: MerchandiseData | null }) => { const basePrice = product?.attributes?.price || 0; let discountedPrice; const currentPromotionalPricing = product?.attributes?.promotionalPricings?.data?.[0]?.attributes; const flatDiscount = currentPromotionalPricing?.flatDiscount; const percentageDiscount = currentPromotionalPricing?.percentageDiscount; if (flatDiscount) { discountedPrice = basePrice - flatDiscount; } else if (percentageDiscount) { discountedPrice = basePrice - (basePrice * percentageDiscount) / 100; } return { discountPrice: discountedPrice, originalPrice: basePrice, amount: flatDiscount || 0, percent: percentageDiscount || 0, ...(!discountedPrice ? null : { amountOff: basePrice - discountedPrice }), }; }; export const getServicePrice = ({ price, promotionalPricingAttributes, }) => { const basePrice = price || 0; let discountedPrice; const currentPromotionalPricing = promotionalPricingAttributes; const flatDiscount = currentPromotionalPricing?.flatDiscount; const percentageDiscount = currentPromotionalPricing?.percentageDiscount; if (flatDiscount) { discountedPrice = basePrice - flatDiscount; } else if (percentageDiscount) { discountedPrice = basePrice - (basePrice * percentageDiscount) / 100; } return { discountPrice: discountedPrice, originalPrice: basePrice, amount: flatDiscount || 0, percent: percentageDiscount || 0, ...(!discountedPrice ? null : { amountOff: basePrice - discountedPrice }), }; }; export default getPrice; //# sourceMappingURL=getPrice.js.map