Pregunta

I have this code on my related products:

<h3>HAVE YOU TRIED...</h3>  
{% assign max = 10 %}
{% assign count = '' %}
{% assign list = '' %}
{% capture list %},{{ product.id }}{% endcapture %}

{% for collection in product.collections %}
    {% if collection.handle contains 'related' %}
        {% for product_related in collection.products %}
            {% capture id %},{{ product_related.id }}{% endcapture %}
            {% unless list contains id %}
                {% if count.size < max and product_related.images.size > 0 %} 
                    <div class="rel-product">
                        <div class="rel-img">
                          {% for image in product_related.images offset:1 limit:1 %}
                                <a href="{{ product_related.url | escape }}"><img src="{{ image.src | product_img_url: 'compact' }}}" alt="" /></a>
                            {% endfor %}
                        </div>

                        <div class="rel-cnt">
                            <h6><a href="{{ product_related.url | escape }}">{{ product_related.title }}</a></h6>
                            <p>{{ variant.option1 }}</p>
                            <span class="price">{{ product_related.price | money }}</span>
                        </div>
                    </div>
                    {% capture count %}{{ count }}.{% endcapture %}
                    {% capture list %}{{ list }}{{ id }}{% endcapture %}
                {% endif %}
            {% endunless %}
        {% endfor %}
    {% endif %}
{% endfor %}

It seems to work fine for products in one collection but not at all for products in another collection, the "have you tried" box is empty. Can anyone tell me what this code is doing in terms of picking related products in shopify and why it might not be showing any related products for items in that collection.

¿Fue útil?

Solución

Firstly print your 'product' array and check what it will return to you while checking for other one.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top