{% cartitems = [{
"id":1,"properties":{"_bundle_sku":"111""},"quantity":1},
{ "id":2,"properties":{"_bundle_sku":"222""},"quantity":1},
{ "id":3,"properties":{"_bundle_sku":"333""},"quantity":1},
{ "id":4,"properties":{"_bundle_sku":"222""},"quantity":1}
}] %}
This is for example I am getting result of my cart items and now I like to keep items together whose _bundle_sku values are same. But I don’t find any help to manipulate cart json object in shopify liquid files.
So here I like the response to achieve like following –
{% cartitems = [{
"id":1,"properties":{"_bundle_sku":"111""},"quantity":1},
{ "id":2,"properties":{"_bundle_sku":"222""},"quantity":1},
{ "id":4,"properties":{"_bundle_sku":"222""},"quantity":1},
{ "id":3,"properties":{"_bundle_sku":"333""},"quantity":1}
}] %}
Please assist me how can I achieve this.
many thanks.
2
Answers
You have to use Javascript. Liquid is not going to be of much help to you. Remember this basic pattern.
You may use Ajax Cart API to do that with a /cart/update.js POST.
Documentation is available here:
https://shopify.dev/docs/themes/ajax-api/reference/cart#post-cart-update-js