Developer forum

Forum » Development » Discount increments existing line

Discount increments existing line

Marco Santos
Reply

Hello.

While trying to reproduce an error, I came across this behaviour:

- I add a product to the cart, PROD1

- I add another product to the cart, PROD2, and increase the quantity to trigger a (custom) discount that offers PROD1 with quantity 1

This all works fine, except that if I then change the quantity for the PROD2 line, while maintaining it in a value that triggers the discount, it increments the amount in the non discount line. So the lines will go from, for example, PROD1:1, PROD2:9, PROD1 (discount):1 to PROD1:2, PROD2:10, PROD1 (discount):1, if I increment from 9 to 10. And it will keep incrementing if I change the amount for PROD2 again.

The discount will always add only one line, the discount one. Here is the code that creates the discount line:

private OrderLine CreateProductOrderLine(Order order, Products.Product product, double quantity = 1.0) {
    OrderLine line = new OrderLine();
 
    line.OrderID = order.ID;
    line.Order = order;
    line.Modified = DateTime.Now;
    line.Quantity = quantity;
    line.ProductID = product.ID;
    line.ProductVariantID = product.VariantID;
    line.ProductName = product.Name;
    line.ProductNumber = product.Number;
    line.Reference = String.Format("Default.aspx?ID={0}&ProductID={1}&VariantID={2}", PageId, product.ID, product.VariantID);
    line.Type = Base.ChkString(Base.ChkNumber(OrderLine.OrderLineType.ProductDiscount));
    line.PageID = PageId;
    line.Product = product;
    line.DiscountID = DiscountID;
 
    return line;
}

This is in version 8.5.1.25. Can you spot anything missing in the created line that coud trigger the behaviour? I have tried setting the tryMerge parameter to false when adding the line to the order, but the behaviour stays the same.

Thanks.


Replies

 

You must be logged in to post in the forum