【问题标题】:Is it possible to dynamically set the "featured" collection on a shopify store?是否可以在 shopify 商店中动态设置“特色”系列?
【发布时间】:2017-04-07 20:56:35
【问题描述】:

我希望能够在 shopify 商店的特色产品部分显示两个不同的系列。我想这样做是为了避免显示与正在查看的产品相同的特色产品。我看到在自定义主题页面上可以选择要显示的集合,但是这个集合不能改变。我认为最好的方法是使用产品标签,然后根据标签更改特色系列。但是我没有成功。非常感谢这里的任何帮助。

{% 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 %}

产品页面上还包含一个“featured-products.liquid”文件,用于控制特色产品部分的布局。可以创建两个显示两个不同集合的文件,然后根据标签显示不同的文件。但是我不确定如何控制在这个文件中显示哪个集合。

<!-- 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>

【问题讨论】:

  • 我不确定我是否会 100% 关注你。您不想在特色部分显示与当前产品相同的产品,对吗?那么,如果您可以检查当前产品句柄是否与特色产品句柄相同并跳过那个,为什么要使用 2 个集合...为什么要为此使用 2 个集合?请说明。
  • @drip 我认为这是避免在推荐部分显示相同产品的最简单方法。我同意您的解决方案确实有意义。那么我该怎么做呢?比较两个产品句柄并使用液体代码从集合中删除产品。
  • 见@ButsAndCats 的回答。

标签: ruby shopify liquid


【解决方案1】:

如果您只想不显示集合中的当前产品,您可以这样做:

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

您可以替换“您的产品在此处。”与指定的任何产品对象here

【讨论】:

  • 什么是我可以替换“您的产品在此处”的示例?
  • 您可能有一个产品网格包括{% include 'product-grid-item' %} 或者您可以只使用{{ product.title }} 进行测试
  • @SpencerM。我想这会对你有所帮助:shopify.com.au/partners/shopify-cheat-sheet
  • 非常有用的链接,当我今晚晚些时候有机会尝试时,会告诉您解决方案是否有效。再次感谢您的帮助,我真的很感激。
  • @SpencerM。您将能够使用“您的产品在此处区域”中的备忘单中的任何 产品对象
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 2014-12-18
  • 1970-01-01
相关资源
最近更新 更多