简体   繁体   English

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

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

I hope someone may be able to help with this. 我希望有人能够对此提供帮助。

I am currently setting up my store with shopify and have duplicated my products for retail and wholesale customers. 我目前正在用shopify建立我的商店,并且已经为零售和批发客户复制了我的产品。

The only issue I am faced with is that the retail products are still showing when a customer with the 'wholesale' tag uses the search box. 我面临的唯一问题是,带有“批发”标签的客户使用搜索框时,零售产品仍在显示。

I was wondering if I add a 'retail' tag to the relevant products, can add any code in search.liquid so that if the customer.tag contains 'wholesale' do not show products with product.tags 'retail' or something along those lines? 我想知道是否可以在相关产品中添加“零售”标签,是否可以在search.liquid中添加任何代码,以便如果customer.tag包含“批发”,则不会显示带有product.tags“零售”或类似内容的产品线?

My current search.liquid looks like: 我当前的search.liquid看起来像:

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

To return only products or pages in results: - http://docs.shopify.com/manual/configuration/store-customization/return-only-product-in-storefront-search-results - Or manually add type=product or type=page to the search URL as a parameter 要仅返回结果中的产品或页面: -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 %}

I am a complete novice and have managed to get by this far following help and tutorials online so any help would be very much appreciated. 我是一个完整的新手,并且已经设法通过网上的帮助和教程获得了到目前为止的帮助,因此非常感谢您的帮助。

I can't afford to subscribe to an additional app at present, such as locksmith and would really like to keep control so I can continue administration in future, 我目前无法订阅其他应用程序,例如锁匠,并且真的想保持控制权,以便将来继续进行管理,

Thanks in advance, 提前致谢,

You may try doing something like that inside the {% if search.performed %} condition. 您可以尝试在{%if search.performed%}条件内执行类似操作。

First get some information about user and store it: 首先获取有关用户的一些信息并将其存储:

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

Explanations : first you assign a false statement to the wholesale status. 说明:首先,您将虚假陈述指定为批发状态。 Then you check if it is customer ( no need to go further if user is not connected). 然后检查是否为客户(如果用户未连接,则无需走更远)。 If he is, then you check if he has a wholesale tag. 如果他是,则您检查他是否具有批发标签。 If he is you assign a true statement. 如果他是您,请给您一个正确的陈述。

Then you are able to display something different this way: 然后,您可以通过这种方式显示不同的内容:

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

Please not that you may have some issues with pagination. 请不要担心您的分页可能会出现问题。

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

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