Discount Error creates 2 CartLines for one Product Variant when using cartLinesAdd mutation

Solved

Discount Error creates 2 CartLines for one Product Variant when using cartLinesAdd mutation

ilya_laska
Visitor
2 0 0

I am getting a weird issue where one CartLine is being split into two due to what seems like a discount rounding error.

I am using Shopify Storefront gQL API.

I add 3 Products that cost $34.99 each. Then I add a discount code that applies a 30% discount to all items.


If I then use the cartLinesUpdate mutation and add another one of these Products, I get a cartLine with 4 products that total $97.98

ilya_laska_0-1701874483297.jpeg

 

HOWEVER If I use the cartLinesAdd mutation and add another one of these Products, my cartLine gets split in two - one cartLine has 3 discounted Products that add up to$73.48, and another has only 1 Product that costs $24.50

ilya_laska_1-1701874588478.jpeg

 

The total ends up being the same either way, yet using a different mutation creates this weird split. In other cases the cartLinesAdd mutation always updates the CartLine when the Cart already has a CartLine with the same ProductVariant.

When I play around with prices to avoid these particular numbers, the issue disappears. I changed my country to get the different currency to show up, and this error didn't appear.
My guess is that cartLinesAdd and cartLinesUpdate seem to differ in their discount rounding implementation and cartLinesAdd "thinks" that it got a different ProductVariant because the discounted price is off by 1 cent after rounding, while cartLinesUpdate simply adds another item to the CartLine

Would be glad to see any confirmation on this, and whether it can be considered a bug by the Shopify team
Thanks in advance

Accepted Solution (1)

SBD_
Shopify Staff
1829 271 414

This is an accepted solution.

Hey @ilya_laska 

 

Thanks for flagging this. Checking with the team and will report back.

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 2 (2)

SBD_
Shopify Staff
1829 271 414

This is an accepted solution.

Hey @ilya_laska 

 

Thanks for flagging this. Checking with the team and will report back.

Scott | Developer Advocate @ Shopify 

ilya_laska
Visitor
2 0 0

I cannot reproduce the issue so it seems you have fixed it a while back.
Thanks for the quick work