Update / delete cart attributes in Shopify

I use cart attributes to add additional information for each product to the cart (from the product page). I specifically use basket attributes on top of position properties , because the client should be able to edit this information in the order later, which position properties do not allow.

Adding information works very well, the problem occurs when the client decides to remove the item from the basket, because although the element is deleted, the basket attribute remains because it is not tied to the product (except for the name of the agreement we give it.)

So, is there a way to update / delete specific basket attributes?

Thanks in advance for your answers!

+4
source share
1 answer

I used the cart attributes since they were entered and found most of the errors associated with them along the way (which Shopify fixed on the way), giving me enough confidence to inform you about this issue.

To edit them, simply place the cart with the same key that you used to create them and change the information. If you specify an empty value, you will delete the key. This is just the key: a store of values. As well as positions, which, incidentally, are edited in my book. I managed to edit them simply by changing the key value, and by specifying the value of the position index, perhaps you overlooked?

In any case, if you take the provided Shopify Javascript API code and explore this small library, you will see the functions used to create the attributes. With a few minor changes, you can introduce your own basket attribute CRUD function to suit your needs.

Here is an old example demonstrating updating the attributes of the basket, the data is a string, i.e.) "attributes [fizz] = 'buzz' (and note that you can save JSON this way):

updateCartAttributes: function(data, callback) { var params = { type: 'POST', url: '/cart/update.js', data: data, dataType: 'json', success: function(cart) { if ((typeof callback) === 'function') { callback(cart); } else { Shopify.api.onCartUpdate(cart); } }, error: function(XMLHttpRequest, textStatus) { Shopify.api.onError(XMLHttpRequest, textStatus); } }; $.ajax(params); } 
+8
source

All Articles