Posted on 30/10/2025 12:11:26
Orderlines of type discount are not merged. OrderLineService.CanBeMerged makes the decision:
The CanBeMerged method determines if two order lines represent the same logical item in the cart — meaning they can be combined into one with an aggregated quantity. It carefully checks product type, variant, unit, and other contextual data before deciding. Here’s the breakdown:
1. Basic null and type checks
If either order line is null, merging isn’t possible.
Special order line types like point products, tax lines, gift cards, and discounts have strict rules:
-
Two point products can merge only if they share the same RewardId, ProductId, and ProductVariantId.
-
A mix of point product and non–point product never merges.
-
Tax lines are always excluded.
-
Gift cards or discounts tied to gift cards never merge (to keep accounting and code tracking distinct).
-
A product discount line can only merge with another product discount line.
2. Regular product lines
For ordinary products (non-BOM, non-gift-card):
Two lines merge if all these match:
-
Same Id, or
-
Same Product.Id, ProductVariantId, UnitId
-
Identical custom OrderLineFieldValues
-
Same StockLocationId
That ensures identical configuration and stock source before aggregation.
3. BOM (Bill of Materials) products
For BOM products, the rule applies recursively:
4. Final equality fallback
If none of the exclusions apply, merging is allowed under the same “ID or product/variant/unit/fields/location” equality logic as standard products.