Pricing Engine & Discounts
Relevant source files
The following files were used as context for generating this wiki page:
- src/Core/Pricing/ARCHITECTURE.md
- src/Core/Domain/Discount/DiscountSettings.php
- src/Core/Domain/SpecificPrice/ValueObject/SpecificPriceId.php
- tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/03_minimumPurchaseAmountFreeGift.ts
- tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/04_minimumPurchaseAmountOnFreeShipping.ts
The Pricing Engine and Discounts system manages the calculation of product prices, application of specific price rules, and management of cart-level discounts. This system ensures that customers receive accurate pricing based on catalog rules, specific price adjustments, and promotional vouchers.
The system distinguishes between product-level "Specific Prices" and cart-level "Discounts" (also known as Cart Rules). The Pricing Engine acts as a central hub for computing these values, while the Domain layer provides the value objects and settings necessary for consistent price handling.
Sources: src/Core/Pricing/ARCHITECTURE.md, src/Core/Domain/Discount/DiscountSettings.php
Pricing Engine Architecture
The Pricing Engine follows a decoupled architecture designed to handle complex price calculations. It separates the core calculation logic from the data sources and specific business rules.
Pricing Flow
The calculation flow involves fetching base prices and sequentially applying adjustments.
The diagram shows the high-level sequence from fetching a raw price to producing a final price including or excluding taxes.
Sources: src/Core/Pricing/ARCHITECTURE.md
Specific Price Management
Specific prices are targeted price adjustments applied to specific products, categories, or customer groups. They are identified by a unique SpecificPriceId.
- SpecificPriceId: A value object that encapsulates the integer identifier for a specific price entry. It validates that the ID is a positive integer.
- Application Logic: Specific prices are applied before cart-level discounts during the price calculation phase.
Sources: src/Core/Domain/SpecificPrice/ValueObject/SpecificPriceId.php:12-40, src/Core/Pricing/ARCHITECTURE.md
Cart Discounts & Rules
Discounts (Cart Rules) are promotions applied at the shopping cart level. These can include free shipping, percentage off, fixed amount off, or free gifts.
Discount Types and Components
| Component | Description |
|---|---|
| Free Gift | Adds a specific product to the cart at no cost when conditions are met. |
| Free Shipping | Removes the transport fees from the order total. |
| Minimum Purchase | A condition requiring a specific threshold (Tax Incl. or Excl.) before the discount applies. |
| Promo Code | A string identifier (voucher) used by the customer to trigger the discount. |
Sources: tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/03_minimumPurchaseAmountFreeGift.ts:39-85, tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/04_minimumPurchaseAmountOnFreeShipping.ts:33-41
Minimum Purchase Amount Logic
Conditions can be set based on the total value of the cart. The system validates these values during creation in the Back Office (BO) and application in the Front Office (FO).
The sequence shows the validation steps when a customer attempts to use a promo code with a minimum purchase requirement.
Sources: tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/04_minimumPurchaseAmountOnFreeShipping.ts:168-175, tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/03_minimumPurchaseAmountFreeGift.ts:192-198
Discount Settings
The DiscountSettings class manages the global configuration for how discounts behave across the store.
- Cumulative Discounts: Determines if multiple discounts can be applied to the same cart.
- Priority: Defines the order in which discounts are applied when multiple are eligible.
Sources: src/Core/Domain/Discount/DiscountSettings.php:24-45
Validation and Constraints
The system enforces strict validation rules for creating discounts to prevent logic errors.
- Name Requirement: Every discount must have a descriptive name.
- Non-Negative Values: Minimum purchase amounts and discount values cannot be less than zero.
- Gift Selection: If the discount type is
free_gift, a valid product must be associated. - Numerical Inputs: The minimum amount value must be a valid number, not text.
Sources: tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/03_minimumPurchaseAmountFreeGift.ts:119-158, tests/UI/campaigns/functional/BO/03_catalog/07_discounts/03_discountV2/04_minimumPurchaseAmountOnFreeShipping.ts:112-143
Summary
The Pricing Engine and Discount system provides a robust framework for managing ecommerce pricing. By separating catalog-level specific prices from cart-level discounts and enforcing strict domain-level validation, the system ensures that promotional logic remains consistent and accurate from the merchant's configuration in the Back Office to the customer's checkout experience in the Front Office.