Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing line item properties on cart in Shopify

Tags:

shopify

cart

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

like image 894
joecritch Avatar asked Sep 25 '12 10:09

joecritch


People also ask

What are line item properties?

Line item properties are used to collect customization information for an item added to the cart. This information can be collected from the buyer on the product page. To learn more about line item properties, see the line_item object Liquid reference.


1 Answers

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.

like image 183
Ziggy Avatar answered Sep 16 '22 18:09

Ziggy