The little box in the button should corresponded with the amount of ordered items already in the cart. This will make the experience less confusing, given that the counter will restart at a refresh. To try to achieve this I have used:
{% for item in cart.items %}
{% case item.id %}
{% when product.id %}
{{item.quantity}}
{% endcase %}
{% endfor %}
And
{% for item in cart.items %}
{% if item.id == product.id %}
{% assign quantity = item.quantity %}
{% endif %}
{% endfor %}
{%- if quantity >= 0 -%}
{{ quantity }}
{%- else -%}
0
{%- endif -%}
It seems to me that liquid is unable to compare these two variables/object data’s with each other. To give a little more context, this code is placed in a snippet.
Thanks for your tip and sorry for my late response.
I’ve tried to implement CartJS but get the following error: Uncaught ReferenceError: CartJS is not defined
I reckon this is because I am editing shopify’s Debut theme which might not have jQuery installed. I can’t quite see if either jquery or cartjs is installed in this theme and I actually rather avoid calling jQuery for this feature only, because of performance reasons. Is this the only way to do this or is there maybe a vanilla alternative to cart.js?
I might try to compare data of the order with information from the {{ cart | json }} object, but I haven’t found a way to decrease the orders when - is pressed.