Display similar product based on metafield or tag

narayaen
Visitor
3 0 0

Hello,

I would like to display a table with products that have the same value in the metafield on the product detail. The code below should work, but unfortunately it doesn't. Do you know where the problem is?

 

{% assign current_product_value = product.metafields.custom.model_barva %}

{% assign related_products = all_products | where: 'metafields.custom.model_barva', current_product_value | where: 'handle', '!=', product.handle %}

{% if related_products.size > 0 %}
<table>
<thead>
<tr>
<th>Produkt</th>
<th>Cena</th>
</tr>
</thead>
<tbody>

{% for related_product in related_products %}
<tr>
<td><a href="{{ related_product.url }}">{{ related_product.title }}</a></td>
<td>{{ related_product.price | money }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
Replies 0 (0)