Product-Recommendations.liquid Problem

PetersDave
New Member
2 0 0

Hi Everyone,

I'm looking for some advice. We are using the warehouse theme and the product recommendations You may also likehave never worked properly from the beginning.

We would like to display the related products in the same way as the CORRECT example below. I've attached the code and hopefully, it will be simple to fix. 

CORRECT DISPLAY! 

https://www.arnoldclarkautoparts.com/collections/bikes/products/tiger-wheelie-kids-12-wheel-balance-...

PetersDave_1-1636458487039.png

 

WRONG DISPLAY - as the You may also like shows unrelated products 

https://www.arnoldclarkautoparts.com/products/tiger-wheelie-kids-12-wheel-balance-training-bike-bicy...

PetersDave_0-1636458015887.png

The code is for the product-recommendations.liquid 

{%- capture section_settings -%}
{
"stackable": false,
"layout": "vertical",
"productId": {{ product.id | json }},
"useRecommendations": {% if product.metafields.sf_related_products.enabled == 1 %}false{% else %}true{% endif %},
"recommendationsCount": 10
}
{%- endcapture -%}

{%- if section.settings.show_product_recommendations -%}
<section class="section" data-section-id="{{ section.id }}" data-section-type="product-recommendations" data-section-settings='{{ section_settings }}'>
<div class="container">
{%- if section.settings.heading != blank -%}
<header class="section__header">
<h2 class="section__title heading h3">{{ section.settings.heading | escape }}</h2>
</header>
{%- endif -%}

<div class="product-recommendations">
{%- if recommendations.performed or product.metafields.sf_related_products.enabled == 1 -%}
<div class="scroller">
<div class="scroller__inner">
<div class="product-list product-list--vertical product-list--scrollable">
{%- comment -%}
If the merchant is explicitly using SuperFields, we use the hand-picked related products, otherwise we
switch to the Shopify automatic recommendation
{%- endcomment -%}

{%- if product.metafields.sf_related_products.enabled == 1 -%}
{%- for i in (1..6) -%}
{%- assign related_product_option = 'product_' | append: i -%}
{%- assign related_product = all_products[product.metafields.sf_related_products[related_product_option]] -%}

{%- unless related_product.empty? -%}
{%- render 'product-item', product: related_product, grid_classes: '1/4--lap 1/5--desk 1/6--wide', show_add_to_cart: section.settings.show_quick_buy -%}
{%- endunless -%}
{%- endfor -%}
{%- else -%}
{%- for product in recommendations.products -%}
{%- render 'product-item', product: product, grid_classes: '1/4--lap 1/5--desk 1/6--wide', show_add_to_cart: section.settings.show_quick_buy -%}
{%- else -%}
{%- comment -%}Hide the section if there is no recommendations to show{%- endcomment -%}
<style>
#shopify-section-{{ section.id }} {
display: none;
}
</style>
{%- endfor -%}
{%- endif -%}
</div>
</div>
</div>
{%- endif -%}
</div>
</div>

{%- comment -%}
--------------------------------------------------------------------------------------
QUICK VIEW CONTAINER
--------------------------------------------------------------------------------------
{%- endcomment -%}

<div id="modal-quick-view-{{ section.id }}" class="modal" aria-hidden="true">
<div class="modal__dialog modal__dialog--stretch" role="dialog">
<button class="modal__close link" data-action="close-modal">{%- render 'icon', icon: 'close' -%}</button>

<div class="modal__loader">
{%- render 'icon', icon: 'search-loader' -%}
</div>

<div class="modal__inner"></div>
</div>
</div>
</section>
{%- endif -%}

{% schema %}
{
"name": "Product recommendations",
"settings": [
{
"type": "checkbox",
"id": "show_product_recommendations",
"label": "Show dynamic recommendations",
"info": "Dynamic recommendations change and improve with time. [Learn more](https://help.shopify.com/en/themes/development/recommended-products)",
"default": true
},
{
"type": "text",
"id": "heading",
"label": "Heading",
"default": "You may also like"
},
{
"type": "checkbox",
"id": "show_quick_buy",
"label": "Show quick buy",
"default": false
}
]
}
{% endschema %}

If you can help me fix this, I'd be happy to connect up. 

Thanks, Dave

 

Replies 0 (0)