UNPKG

@unchainedshop/plugins

Version:

Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec

45 lines 1.74 kB
import { ProductPricingAdapter, ProductPricingDirector, } from '@unchainedshop/core'; export const ProductRound = { ...ProductPricingAdapter, key: 'shop.unchained.pricing.product-round', version: '1.0.0', label: 'Round product price', orderIndex: 90, isActivatedFor: () => { return true; }, settings: { defaultPrecision: 5, roundTo: (value, precision) => Math.round(value / precision) * precision, }, configure({ defaultPrecision, roundTo }) { if (defaultPrecision) this.settings.defaultPrecision = defaultPrecision; if (roundTo) this.settings.roundTo = roundTo; }, actions: (params) => { const pricingAdapter = ProductPricingAdapter.actions(params); return { ...pricingAdapter, calculate: async () => { const { currency } = params.context; const { defaultPrecision, roundTo } = ProductRound.settings; const { calculation = [] } = params.calculationSheet; if (calculation?.length) { pricingAdapter.resultSheet().resetCalculation(params.calculationSheet); calculation.forEach((item) => { const newAmount = roundTo(item.amount, defaultPrecision, currency); pricingAdapter.resultSheet().calculation.push({ ...item, amount: newAmount, }); }); } return pricingAdapter.calculate(); }, }; }, }; ProductPricingDirector.registerAdapter(ProductRound); //# sourceMappingURL=product-round.js.map