Posted on 27/03/2019 12:17:16
Hi Aki
There are a lot of things in play when deciding if orderlines should be merged or not. I.e. variantid, unit, custom orderline fields etc. So I would find the 2 orderlines in the database and locate the difference as that would give you a pointer.
For reference and problem location, please refer to this code that holds the logic for when orderlines are merged or not.
BR NIcolai
Public Function CanBeMerged(orderLine As OrderLine, another As OrderLine) As Boolean
If orderLine Is Nothing OrElse another Is Nothing Then
Return False
End If
If (orderLine.HasType(OrderLineType.PointProduct) AndAlso another.HasType(OrderLineType.PointProduct)) Then
Return Not (IsNothing(orderLine.RewardId) OrElse IsNothing(orderLine.RewardPoints) OrElse IsNothing(another.RewardId) OrElse IsNothing(another.RewardPoints) OrElse
orderLine.RewardId.Value <> another.RewardId.Value OrElse String.Equals(orderLine.ProductId, another.ProductId, StringComparison.Ordinal) OrElse
String.Equals(If(orderLine.ProductVariantId, String.Empty), If(another.ProductVariantId, String.Empty), StringComparison.Ordinal) OrElse
String.Equals(orderLine.Product.LanguageId, another.Product.LanguageId, StringComparison.Ordinal))
End If
If orderLine.HasType(OrderLineType.PointProduct) OrElse another.HasType(OrderLineType.PointProduct) Then
Return False
End If
If orderLine.Product.Type = ProductType.GiftCard OrElse another.Product.Type = ProductType.GiftCard OrElse
(orderLine.HasType(OrderLineType.Discount) AndAlso Not String.IsNullOrEmpty(orderLine.GiftCardCode)) OrElse
(another.HasType(OrderLineType.Discount) AndAlso Not String.IsNullOrEmpty(another.GiftCardCode)) Then
Return False
End If
If (orderLine.HasType(OrderLineType.ProductDiscount) AndAlso Not another.HasType(OrderLineType.ProductDiscount)) OrElse
(Not orderLine.HasType(OrderLineType.ProductDiscount) AndAlso another.HasType(OrderLineType.ProductDiscount)) Then
Return False
End If
If Not orderLine.Product.Type = ProductType.Bom Then
Return String.Equals(orderLine.Id, another.Id, StringComparison.Ordinal) OrElse
(String.Equals(orderLine.Product.Id, another.Product.Id, StringComparison.Ordinal) AndAlso
String.Equals(If(orderLine.ProductVariantId, String.Empty), If(another.ProductVariantId, String.Empty), StringComparison.Ordinal) AndAlso
String.Equals(If(orderLine.UnitId, String.Empty), If(another.UnitId, String.Empty), StringComparison.Ordinal) AndAlso
orderLine.OrderLineFieldValues.Equals(another.OrderLineFieldValues)
)
End If
For Each thisBomItem As OrderLine In orderLine.BomOrderLines
Dim matchFound As Boolean = False
For Each otherBomItem As OrderLine In another.BomOrderLines
If CanBeMerged(thisBomItem, otherBomItem) Then
matchFound = True
End If
Next
If Not matchFound Then
Return False
End If
Next
Return String.Equals(orderLine.Id, another.Id, StringComparison.Ordinal) OrElse
(String.Equals(orderLine.Product.Id, another.Product.Id, StringComparison.Ordinal) AndAlso
String.Equals(If(orderLine.ProductVariantId, String.Empty), If(another.ProductVariantId, String.Empty), StringComparison.Ordinal) AndAlso
String.Equals(orderLine.UnitId, another.UnitId, StringComparison.Ordinal) AndAlso
orderLine.OrderLineFieldValues.Equals(another.OrderLineFieldValues))
End Function