Skip to main content

Product Price Rounding

Rounds all product pricing calculations to a configurable precision. Typically runs last in the product pricing chain.

Installation​

import '@unchainedshop/plugins/pricing/product-round';

How It Works​

  1. Takes all existing calculation items
  2. Rounds each amount to the configured precision
  3. Replaces the original calculation with rounded values

Configuration​

Configure the rounding behavior before starting the engine:

import { ProductRound } from '@unchainedshop/plugins/pricing/product-round';

// Round to nearest 5 cents (default)
ProductRound.configure({
defaultPrecision: 5,
});

// Round to nearest 10 cents
ProductRound.configure({
defaultPrecision: 10,
});

// Custom rounding function (e.g., always round up)
ProductRound.configure({
defaultPrecision: 5,
roundTo: (value, precision, currencyCode) => {
return Math.ceil(value / precision) * precision;
},
});

Default Settings​

SettingDefaultDescription
defaultPrecision5Round to nearest 5 cents
roundToStandard roundingMath.round(value / precision) * precision

Currency-Specific Rounding​

The roundTo function receives the currency code, enabling currency-specific logic:

ProductRound.configure({
defaultPrecision: 5,
roundTo: (value, precision, currencyCode) => {
if (currencyCode === 'JPY') {
// Japanese Yen has no decimal places
return Math.round(value);
}
return Math.round(value / precision) * precision;
},
});

Adapter Details​

PropertyValue
Keyshop.unchained.pricing.product-round
Version1.0.0
Order Index90
Sourcepricing/product-round.ts