0
votes

I would like to be able to display two different collections in the featured products section on a shopify store. I would like to do this to avoid displaying a featured product that is the same as the product being viewed. I see that on the customize theme page it is possible to chose which collection to be displayed, but this collection cannot change. I believe the best way to do this is to use product tags and then change the featured collection based on the tag. However I have not had success. Any help here is greatly appreciated.

{% for tag in product.tags %}

    {% if tag contains 'top' %}

        {% assign settings.home_featured_products == 'Home' %}

    {% elsif tag contains 'bottom' %}

        {% assign settings.home_featured_products == 'Frontpage' %}

    {% endif %}

{% endfor %}

There is also a "featured-products.liquid" file that is included on the product page that controls the layout of the featured products section. It may be possible to create two of these files that show two different collections and then display the different files based on tags. However I am not sure how to control which collection is displayed in this file.

<!-- snippets/featured-products.liquid -->

{% if section_number > 1 and number_of_index_sections > 1 %}
 <hr class="hr--medium hr--clear">
{% endif %}

<div class="section-header text-center">
  <h1>{{ 'home_page.sections.featured_products' | t }}</h1>
  <hr class="hr--small">
</div>

<div class="{% if settings.collection_products_grid == 'collage' %}grid grid-collage{% else %}grid-uniform{% endif %}">

  {% comment %}
    Loop through products in your Frontpage collection.
    This collection is created by default, but you must add products to it.

    See the snippet 'snippets/product-grid-collage.liquid'.

    `is_reverse_row_product`, `three_row_index_product`, `collection_product_count_product`, and `divisible_by_three_product` are
    all used by 'snippets/product-grid-collage.liquid'
  {% endcomment %}
  <div class="grid-uniform__aligner">
  {% if settings.home_featured_products == blank or collections[settings.home_featured_products].empty? or collections[settings.home_featured_products].products_count == 0 %}

    {% comment %}
      For onboarding new users to your theme, we add some default products and onboarding tutorials to help populate their store
    {% endcomment %}
    {% unless emptyState %}
      {{ 'theme-onboarding.css' | global_asset_url | stylesheet_tag }}
      {% assign emptyState = true %}
    {% endunless %}

    {% include 'onboarding-featured-products' %}

  {% else %}

    {% if settings.collection_products_grid == 'collage' %}

      {% assign is_reverse_row__product = false %}
      {% assign three_row_index__product = 0 %}
      {% if collections[settings.home_featured_products].products_count > 50 %}
        {% assign collection_product_count__product = 50 %}
      {% else %}
        {% assign collection_product_count__product = collections[settings.home_featured_products].products_count %}
      {% endif %}
      {% assign divisible_by_three__product = collection_product_count__product | modulo:3 %}

      {% for product in collections[settings.home_featured_products].products %}
        {% include 'product-grid-collage' %}
      {% endfor %}

    {% else %}

      {% assign grid_item_width = 'medium--one-half large--one-third' %}
      {% for product in collections[settings.home_featured_products].products %}
        {% include 'product-grid-item' %}
      {% endfor %}

    {% endif %}

  {% endif %}
  </div>
</div>
1
I'm not sure I follow you at 100%. You like to not show the same product as the current one on the featured section, right? Then why use 2 collections if you can just check if the current product handle is the same as the featured one and skip that one... Why use 2 collections for this? Please specify.drip
I agree with drip:Buts
@drip I thought that this would be the simplest way to avoid having the same product being displayed in the recommended section. I do agree that your solution does make sense. So how would I go about doing this? Comparing both product handles and removing a product from the collection with liquid code.JSON_Derulo
See @ButsAndCats answer.drip

1 Answers

1
votes

If all you want to do is not display the current product in the collection you can just do this:

{% assign handle = product.handle %}
{% for product in collection[featured_products].products %}
  {% unless product.handle == handle %}
    Your product goes here.
  {% endunless %}
{% endfor %}

You can replace 'Your product goes here.' with any of the product objects specified here