What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: Shopify Discount Functions: Duplicate line items in checkout

Shopify Discount Functions: Duplicate line items in checkout

VitaDev
Shopify Partner
12 0 4

I am currently developing a function to apply some custom product discount logic. The function applies discounts to a certain quantity of a product variant, which may result in a line item split. In the cart everything works fine. The problem occurs when I continue to checkout. Instead of having two line items - one for the discounted item and one for the non-discounted item - I get an additional non-discounted line item. It has the quantity of the discounted line item, the quantity is substracted from the other non-discounted line. So the total number of products is correct, but having this additional line item is a problem.
As far as I understand, the output of a function that applies product discounts can only be an array containing discounts including their targets. The targets are identified by variant IDs and I can specify the quantity that should be discounted. So I do not really see room for changes here. Also, I do not understand why the problem only occurs in the checkout. The automatic app discount is the only active discount and the function output is exactly one discount with multiple targets.
Does anybody have an idea what I need to do to remove the additional line items in checkout? I appreciate any help on this.

Replies 3 (3)

VitaDev
Shopify Partner
12 0 4

EDIT: I now noticed that this always happens when the discounted line item comes after the non-discounted one (of the same product variant) in the cart. When the discounted line item comes before, there is no additional line in checkout. It seems like - when going to checkout - Shopify takes the lines from the already splitted cart and applies function discounts to the first line item with the specified variant ID and splits the line if necessary. I still got no solution for this, since I am not sure if I can tell Shopify to always put the discounted line first. Anyways, the behaviour seems not optimal to me.

j-riv
Shopify Partner
11 1 0

Did you ever contact Shopify about this? Or figure out what was happening? I seem to be having a similar issue, but I'm using standard automatic discounts. Im even sometimes getting 0 quantity 0 price line items. Its really weird.

VitaDev
Shopify Partner
12 0 4

That's indeed weird. I noticed this might have been the wrong board for asking this question, so I did it again in the Shopify Functions board: https://community.shopify.com/c/shopify-functions/product-discounts-duplicate-line-items-in-checkout... A Shopify staff member replied and finally told me Shopify is aware of a problem there and is working on a fix.