Shopify/Timber

Cart and Change.js - Ajax cart treats inventory different to normal cart

Opened this issue · 0 comments

Issue

There's a discrepancy we found that the AJAX Cart doesn't update the quantity of an item if it doesn't have anymore quantity to add (which makes sense, although it should show error that no more available which it doesn't) - we are also using .split in Shopify script.

Through normal cart, I can increase quantity of this item to 10 with no worries and click "update cart" and still shows 10. Only when I go to checkout does it actually show an error which is a poor UX for the customer.

The discrepancy between the two types of carts meant that we didn't know we didn't have enough inventory to cover it because the ajax cart kept removing the items that we added in the liquid cart.

Replicate

1 - Through Shopify script, split an item after 1 and add 3 to cart (through liquid cart, non ajax cart), see that it splits correctly.

Split example:

if original_line_item.quantity >= 1
   new_line_item = original_line_item.split(take: 1)
   new_line_item.change_line_price(Money.new(cents: 500), message: "Third hat for 5 dollars")
  cart.line_items << new_line_item
end

2 - Open ajax cart, see 2 different items,
3 - Click update quantity of either items. Notice that the item gets removed from the cart.