簡體   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