I’m trying to cycle over all my product.id in my cart.
I have a various product with the same product.id but different line_item.
Example:
line.item[1]: productID 2756695130141
line.item[2]: productID 2756695130141
line.item[3]: productID 2756702765085
line.item[4]: productID 2756695130141
I want to know how many different productID I have (in this case, 2). How can I do this in Liquid/Shopify?
3
Answers
I think this code may help you
Please write back if this is not the solution you are looking for.
EDIT
Best way to do that is to use arrays. Because they have
map
andunique
.This code will return array of unique product IDs
This code will return concatenated string of unique product IDs
Documentation about
Array filters
in liquid: https://help.shopify.com/themes/liquid/filters/array-filters// Best and easy solution
{% for item in cart.items %}
{{item.product.id}}
{% endfor %}`