Developer forum

Forum » Ecommerce - Standard features » Discount lines not merged

Discount lines not merged

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have an order in the database with these lines (among others):

These lines are two discounts for a free product coming from a free product discount:

The order has two normal product lines hence the two free products.

But should these lines have been merged when creating the cart? Or are discount lines never merged? I checked CanBeMerged in the OrderLineService and can't see why they would not be merged; in the database, *all* fields are identical except for Id, ParentLineId and AutoId.

The duplicates are causing issues when synchronizing over OData to BC as the two lines are treated as a Post followed by a Patch; not two Posts or a single Post with a quantity of 2.

Imar


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

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:

  • Each BOM item in the first line must find a matching item in the other line (using the same CanBeMerged logic).

  • Only when all components match do the parent BOM lines merge.

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.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I'm a little confused :-) You say:

>> Orderlines of type discount are not merged. 

and 

>> A product discount line can only merge with another product discount line.

My two discount lines are both of type 3 (ProductDiscount) so shouldn't they merge? For the record, my image shows only the two discount lines, not the product lines.

Imar

 

You must be logged in to post in the forum