繁体   English   中英

隐藏基于客户标签Shopify search.liquid的产品

[英]Hiding products based on customer tag Shopify search.liquid

我希望有人能够对此提供帮助。

我目前正在用shopify建立我的商店,并且已经为零售和批发客户复制了我的产品。

我面临的唯一问题是,带有“批发”标签的客户使用搜索框时,零售产品仍在显示。

我想知道是否可以在相关产品中添加“零售”标签,是否可以在search.liquid中添加任何代码,以便如果customer.tag包含“批发”,则不会显示带有product.tags“零售”或类似内容的产品线?

我当前的search.liquid看起来像:

<!-- /templates/search.liquid -->
{% comment %}

要仅返回结果中的产品或页面: -http : //docs.shopify.com/manual/configuration/store-customization/return-only-product-in-storefront-search-results-或手动添加type = product或type =将页面作为搜索网址作为参数

{% endcomment %}

{% comment %}
  Check to enforce respond.js
{% endcomment %}
{% assign respond_js_secret_key = shop.domain | md5 %}
{% unless search.terms == respond_js_secret_key %}

{% comment %}
  Avoid accessing search.results before the opening paginate tag.
  If you do, the pagination of results will be broken.
{% endcomment %}
{% paginate search.results by 12 %}

  <div class="grid">
    <div class="grid__item">
      <header class="section-header text-center">
        {% if search.performed %}
          {% if search.results_count == 0 %}
            <h1 class="text-center">{{ 'general.search.no_results_html' | t: terms: search.terms }}</h1>
          {% else %}
            <h1 class="text-center">{{ 'general.search.results_for_html' | t: terms: search.terms }}</h1>
          {% endif %}
        {% else %}
          <h1 class="text-center">{{ 'general.search.title' | t }}</h1>
        {% endif %}
        <hr class="hr--small">
      </header>

      {% include 'search-bar', search_btn_style: 'btn', search_bar_location: 'search-bar--page' %}

      {% if search.performed %}

        <hr class="hr--medium hr--clear">

        <div class="grid-uniform">

          {% for item in search.results %}
{% assign itemIswholesale = false %}
{% if item.tags contains 'wholesale' or item.title contains 'wholesale' %}
{% assign itemIswholesale = true %}
{% endif %}

{% if itemIswholesale and customer and customer.tags contains 'wholesale' %}
{% if item.object_type == 'product' %}
{% assign product = item %}
{% include 'product-grid-item' %}
{% else %}
<div>
<div>
<a href="{{ item.url }}">
<span>
<span>{{ item.title }}</span>
{{ item.content | strip_html | truncatewords: 60 }}
</span>
</a>
</div>
</div>
{% endif %}
{% else %}
{% unless itemIswholesale %} 
{% if item.object_type == 'product' %}
{% assign product = item %}
{% include 'product-grid-item' %}
{% else %}
<div>
<div>
<a href="{{ item.url }}">
<span>
<span>{{ item.title }}</span>
{{ item.content | strip_html | truncatewords: 60 }}
</span>
</a>
</div>
</div>
{% endif %}
{% endunless %}
{% endif %}
{% endfor %}
        </div>

        {% if paginate.pages > 1 %}
          {% include 'pagination' %}
        {% endif %}

      {% endif %}

    </div>
  </div>

{% endpaginate %}

{% else %}
  {% include 'respond' %}
  {% layout none %}
{% endunless %}

我是一个完整的新手,并且已经设法通过网上的帮助和教程获得了到目前为止的帮助,因此非常感谢您的帮助。

我目前无法订阅其他应用程序,例如锁匠,并且真的想保持控制权,以便将来继续进行管理,

提前致谢,

您可以尝试在{%if search.performed%}条件内执行类似操作。

首先获取有关用户的一些信息并将其存储:

{% assign wholesale = false %}
{% if customer %}
  {% assign customer_tags = customer.tags | split: "," %}
  {% if customer_tags contains 'wholesale' %}
    {% assign wholesale = true %}
  {% endif %}
{% endif %}

说明:首先,您将虚假陈述指定为批发状态。 然后检查是否为客户(如果用户未连接,则无需走更远)。 如果他是,则您检查他是否具有批发标签。 如果他是您,请给您一个正确的陈述。

然后,您可以通过这种方式显示不同的内容:

{% for result in search.results %}
  {% if wholesale %}
    Do something
  {% else %}
    Do something else
  {% endif %}
{% endfor %}

请不要担心您的分页可能会出现问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM