user3246722
user3246722

Reputation: 47

Shopify - If item in cart belongs to a specific collection

I am a newbie at Shopify and have been struggling with this issue for the past few days. This might be a simple thing but I just can't find a solution for it.

This is for a swimwear store. I have two collections (Collection 2013 and Collection 2014). In Collection 2014 you can buy the pieces (Top and Bottom) in separate sizes. But for Collection 2013 you can only buy both pieces in the same size. Basically, I just want to identify what collection an item inside the cart belongs to and display a specific information in the cart description. For example:

This is what I have tried but with no luck:

...

{% for item in cart.items %}

...

<td>
    <a href="{{item.product.url }}">
        {{ item.product.title }} <br>
        {% for c in cart.items %}
            {% if c.handle == "collection-2014" %}
                TOP: {{ item.variant.option1 }} - BOTTOM: {{ item.variant.option2 }}
            {% elsif c.handle == "collection-2013" %}
                SIZE: {{ item.variant.option1 }}
            {% endif %}
         {%endfor %}
    </a>
</td>

...

{% endfor %}

...

Any help will be extremly appreciated! Thank you very much in advanced!

Upvotes: 0

Views: 4884

Answers (1)

Steph Sharp
Steph Sharp

Reputation: 11682

The problem is you are looking for the collection in cart.items instead of item.product.collections.

Try this:

<td>
    <a href="{{ item.product.url }}">
        {{ item.product.title }} <br />
        {% for collection in item.product.collections %}
            {% if collection.handle == "collection-2014" %}
                TOP: {{ item.variant.option1 }} - BOTTOM: {{ item.variant.option2 }}
            {% elsif collection.handle == "collection-2013" %}
                SIZE: {{ item.variant.option1 }}
            {% endif %}
         {% endfor %}
    </a>
</td>

Upvotes: 2

Related Questions