joecritch
joecritch

Reputation: 1105

Changing line item properties on cart in Shopify

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'?

Upvotes: 8

Views: 7271

Answers (1)

Ziggy
Ziggy

Reputation: 22375

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.

Upvotes: 6

Related Questions