Product Discount
Applies discounts to product-level pricing. Works in conjunction with discount adapters that provide discount configurations.
Included in Base Preset
Registered automatically by registerBasePlugins() / registerAllPlugins().
Registration
import { pluginRegistry } from '@unchainedshop/core';
import { ProductDiscountPlugin } from '@unchainedshop/plugins/pricing/product-discount';
pluginRegistry.register(ProductDiscountPlugin);
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 |
Related
- Discount Half Price Manual - Example discount adapter targeting this pricing adapter
- Discount 100 Off - Fixed amount discount
- Order Discounts - Creating custom discounts