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
- Iterates through all active discounts on the order
- For each discount, resolves the configuration (supports custom resolvers)
- Calculates the discount amount based on the item total
- Adds discount and tax adjustments to the calculation
Discount Configuration
Discounts can specify:
| Property | Description |
|---|---|
rate | Percentage discount (0.1 = 10%) |
fixedRate | Fixed amount in cents |
isNetPrice | Whether amount is net (before tax) |
taxRate | Specific 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
| Property | Value |
|---|---|
| Key | shop.unchained.pricing.product-discount |
| Version | 1.0.0 |
| Order Index | 30 |
| Source | pricing/product-discount.ts |
Related
- Discount Half Price - Example discount adapter
- Discount 100 Off - Fixed amount discount
- Order Discounts - Creating custom discounts