258 votes
0 answers
liquid - Shopify search for related products is not returning similar tagged products
Solution:
Due to the loop limit of 50 products. I filtered the all.products by collection first (excluding all collection and current product) and then iterating to render.
{% if collection == null or collection.handle == 'frontpage' or collection.handle == 'all' %}
{% assign found_a_collection = false %}
{% for c in product.collections %}
{% echo c %}
{% if found_a_collection == false and c.handle != 'frontpage' and c.handle != 'all-products' and c.all_products_count > 1 %}
{% assign found_a_collection = true %}
{% assign collection = c %}
{% endif %}
{% endfor %}
{% endif %}
<div class="container custom-related-product">
<section>
<div>
{% if section.settings.product_recommendations_heading != blank %}
<div class="twelve{% unless settings.borders_enable %} bottompad{% endunless %}">
<h2 class="text-center">{{ section.settings.product_recommendations_heading }}</h2>
</div>
{% endif %}
<div class="product-loop center">
{% for similar_product in collection.products %}
{% if similar_product.handle != product.handle %}
{% render 'product.loop', product: similar_product, block_width: 'three' %}
{% assign related_products = related_products | plus: 1 %}
{% if related_products == 4 %}
{% break %}
{% endif %}
{% endif %}
{% endfor %}
</div>
</div>
</section>
</div>
Undefined asked
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.