SERIOUS BUG: using change_properties results in a broken cart

Tourist
8 0 3

If you use change_properties, and add a product more than once to cart, that product's line item starts to behave strangely with cart updates:

1. if you add/remove 1 from the quantity, instead of changing by 1 it will increment/decrement by the original quantity. IE, add a product to cart three times, go to cart, set quantity to 4 & submit, quantity will change to 6

2. If you click remove (ie, go to /cart/change?line=1&quantity=0) it will decrement the quantity by one. Unless you've incremented it, as above, in which the first remove will delete all line items you added with update quantities + 1, and subsequent removes will decrement by 1 until you get to zero.

3. If you happen to split the line item in the script, the cart behaves even more oddly in ways I did not attempt to quantify further.

4. The issue persists to checkout.

I tested using both html & ajax carts. Cart Script ID 8486920 is a simple demonstration. It has the following contents:

 

Input.cart.line_items.each do |i|
  i.change_properties({ '_dinfo' => "test" }, message:"")
end
Output.cart = Input.cart 
1 Like
Shopify Expert
704 0 68

3. If you happen to split the line item in the script, the cart behaves even more oddly in ways I did not attempt to quantify further.

^ THIS!

I'm a million different people
0 Likes
Shopify Expert
704 0 68

Michael! I did some investigation on my own script that is creating bundles and although I haven't solved yet I think it might be as a result of duplicate IDs created when the line item is split out and duplicated. Whether you use a simple form submit or AJAX there is likely to be some conflict...

 

I'm a million different people
0 Likes
Highlighted
Shopify Expert
704 0 68

From somebody who would know: 

try updating quantities based on line item index, rather than ID

jQuery.post('/cart/change.js', { line: 1, quantity: 1 });
I'm a million different people
0 Likes
Tourist
8 0 3

@rickydazla: in some cases it breaks checkout even if you don't change line item quantities before checking out. And it breaks changing quantities regardless of whether you use ajax or simple form, or whether you use id or index.

Shopify did eventually confirm the bug, as of Feb 9, 2018. Since then there's been no update.The bug is still present, and our deal management tool is still on hold.

Cart scripts as documented remain broken in a way that will completely destroy customer confidence for any customer that encounters it.

Having confirmed the bug, you'd think shopify would at least be decent enough to note in the documentation that `change_properties` is broken and SHOULD NOT be used.

Any cart script that uses it WILL result in wrong behaviour for customers who change quantities in their cart, by any method.

I suspect from other posts that you can/will trigger the bug if you use the ajax cart to change line item properties as well, but I don't have occasion to test it. Pretty sure the underlying error is an aliasing error, and adding/changing line properties creates a new copy of the line item and some parts of the cart/checkout code retain a reference to the old copy.

0 Likes
New Member
1 0 0

This continues to be an issue. Michael described the weirdness and inconsistency well above.


Main issues:

- Line item properties persisting even after they have been added and then completely removed with a script.

- Lack of proper documentation. For example /cart/change.js does not support changing "properties" when you pass ID but it does when you pass "line" ... not documented anywhere. the /cart/updates.js documentation shows a request that's just invalid and returns a 404 when constructed in that format.

- Overall inconsistency in behavior after modifying line items with a script. So many inconsistencies to the point it's just hard to describe.

 

Ugh.

0 Likes