Skip to main content

Product Discount

Applies discounts to product-level pricing. Works in conjunction with discount adapters that provide discount configurations.

Included in Base Preset

This plugin is part of the base preset and loaded automatically. Using the base preset is strongly recommended, so explicit installation is usually not required.

Installation

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

How It Works

  1. Iterates through all active discounts on the order
  2. For each discount, resolves the configuration (supports custom resolvers)
  3. Calculates the discount amount based on the item total
  4. Adds discount and tax adjustments to the calculation

Discount Configuration

Discounts can specify:

PropertyDescription
ratePercentage discount (0.1 = 10%)
fixedRateFixed amount in cents
isNetPriceWhether amount is net (before tax)
taxRateSpecific tax rate to apply

Custom Price Configuration Resolver

Discounts can provide a customPriceConfigurationResolver function for dynamic discount logic:

const configuration = {
rate: 0.1,
customPriceConfigurationResolver: (product, quantity, config) => {
// Custom logic based on product, quantity, or configuration
if (product.tags?.includes('sale')) {
return { rate: 0.2 }; // 20% off sale items
}
return { rate: 0.1 }; // 10% off regular items
},
};

Adapter Details

PropertyValue
Keyshop.unchained.pricing.product-discount
Version1.0.0
Order Index30
Sourcepricing/product-discount.ts