Je možné zistiť, či sa položka už nachádza v košíku a či sa na stránke produktu pridá trieda div?
Dúfam, že niečo ako:
{% for line_item in cart.items %}
{% if line_item.title = product.title %}
{% assign incart = "in-cart" %}
{% endif %}
{% endfor %}
by to urobilo: {% if line_item.title = product.title %}
ale Shopoff sa to nepáči Myšlienky?
odpovede:
0 pre odpoveď č. 1line_item.title sa líši od product.title. Pretože line_item.title je variantom produktu, ktorý je v košíku. Povedzme, že názov produktu je Shirt A line_item.title bude Shirt-Red (červená varianta)
Skúste to line_item.product.title
0 pre odpoveď č. 2
Skúste niečo takéto:
{% assign in_cart = false %}
{% for item in cart.items %}
{% if item.product.handle == product.handle %}
{% assign in_cart = true %}
{% endif %}
{% endfor %}
{% if in_cart == true %}
Product is already in the cart...
{% endif %}
Upozorňujeme tiež, že vo vyhlásení if by ste mali používať ==
, nie =
.