7

Is it possible to change line item properties after they have been added to the cart? (Either via a normal form submission, or via AJAX?)

I've tried a POST to /cart/change with a "properties[MyProperty]" key, but no luck so far. This is coupled with the line parameter to denote the unique line item.

Any ideas? Or is it just a straight 'no'?

joecritch
  • 1,095
  • 2
  • 10
  • 25
  • 2
    I'm having this problem to. As a work around I am removing and re-adding the line-item each time ToT; – Ziggy Jan 30 '13 at 00:08
  • I know this question is ancient but for anyone wondering, this is possible using line item as the identifier. [Check out this answer](https://ecommerce.shopify.com/c/ecommerce-design/t/edit-line-item-properties-from-cart-362790#comment-545035) – bug56 Dec 04 '18 at 05:55

1 Answers1

6

Using Shopify's API you can't use cart/change.js to change the properties of a line item. The reason is that cart/change.js uses 'properties' to find the line item you want. The API documentation omits this. Here is an example:

When I make a POST to cart/add.js with the following url encoded parameters:

quantity=9403&id=278440178&properties%5Bmy-property%5D=property%20BAR

The response will include,

"properties":{"my-property":"property BAR"}

When I go on to make a POST to cart/change.js to change the property from BAR to FOO,

id=278440178&properties%5Bmy-property%5D=property%20FOO

Then the response will include,

"properties":{"my-property":"property BAR"}

That is, I was unable to change the line item property this way. You may suspect that this is because there is some trick to the cart/change.js API, but this is not the case.

Notice, when I try to remove a line item by making a POST to cart/change.js and specifying quantity=0, like this:

quantity=0&id=278440178&properties%5Bmy-property%5D=property%20FOO

With the property property FOO being one that does not belong to any item (my cart only has an item with property BAR right now), the item is not removed from the cart. If on the other hand I do this:

POST: quantity=0&id=278440178&properties%5Bmy-property%5D=property%20BAR

The item is removed as normal.

Conclusion: in cart/change.js, shopify uses line-item properties in the same way it uses 'id', that is, to find the line item whose quantity you want to change. Just in the same way that you can't use cart/change.js to change the id of a line item, you can't use it to change the properties of one.

Ziggy
  • 21,845
  • 28
  • 75
  • 104
  • 1
    I'm so glad I finally figured this out. I've had this tab open for a month! – Ziggy Feb 20 '13 at 02:25
  • so how doe one change line item properties from the cart? Do you have to remove the thing from the cart and re-add it? – Spencer Williams Apr 25 '13 at 20:17
  • Unfortunately, that's the way I ended up doing it. I include the POST to add as a callback on the call to remove. There are many things we could wish for the Shopify API to do better... Maybe there is hope, perhaps you will discover a better way of doing this. If you do, make sure to let me know! – Ziggy Apr 26 '13 at 19:52