Issue
Can anyone help me finish my code here? I'm trying to filter search results by only showing products tagged with a tag that matches customer tags.
For example, a customer (tagged with "Mustang") searches Ford on the front end. (Normally - all Ford products would be displayed.) However, If the customer is tagged Mustang, only products tagged Mustang would display.
Here's what I have so far; the results aren't empty, but they do not display.
{% for item in search.results %}
{% if item.object_type == 'product' %}
<!-- for tag in product tags do -->
{% for tag in product.tags %}
<!-- If tag in product tags do -->
{% if tag contains customer.tags %}
{% assign product = item %}
{% include 'product-grid-item' %}
{% endif %}
{% endfor %}
{% else %}
<div class="grid__item medium-up--one-third small--one-half">
<h2 class="h3">{{ item.title | link_to: item.url }}</h2>
<p>{{ item.content | strip_html | truncatewords: 50 }}</p>
</div>
{% endif %}
{% endfor %}
Solution
There is no product.tags
in the search result, it should be item.tags
{% for item in search.results %}
{% if item.object_type == 'product' %}
<!-- for tag in product tags do -->
{% for tag in item.tags %}
<!-- If tag in product tags do -->
{% if customer.tags contains tag %}
{% assign product = item %}
{% include 'product-grid-item' %}
{% endif %}
{% endfor %}
{% else %}
<div class="grid__item medium-up--one-third small--one-half">
<h2 class="h3">{{ item.title | link_to: item.url }}</h2>
<p>{{ item.content | strip_html | truncatewords: 50 }}</p>
</div>
{% endif %}
{% endfor %}
Answered By - Charles C. Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.