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'?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With