Question

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:

  • if an item inside the cart belongs to collection 2014, display: TOP: S - BOTTOM: M
  • if an item inside the cart belongs to collection 2013, display: SIZE: M

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!

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top