【问题标题】:How to limit Shopify search input to a specific collection?如何将 Shopify 搜索输入限制为特定集合?
【发布时间】:2021-04-01 20:57:05
【问题描述】:

我正在尝试创建一个仅在集合中搜索/过滤结果的搜索输入。

这是搜索模板:

<div id="col-main" class="page-search">

{% if search.results_count == 0 or search.performed == false %}
  <h4 class="title">{{ 'search.general.heading' | t: count: search.results_count }}: {{ 'search.general.results_with_count' | t: terms: search.terms, count: search.results_count }}</h4>

  <form class="search-form" action="/search">
    <input type="hidden" name="type" value="product" />
    <input type="hidden" name="options[prefix]" value="last" />
    <input type="text" name="q" class="search_box" placeholder="{{settings.search_placeholder}}" value="{{ search.terms }}" />

    <button type="submit" class="search-submit" title="Search">
      {% if settings.search_icon_type == 'font-icon' %}
        <i class="demo-icon {{ settings.search_font_icon }}"></i>
      {% else %}
        <img src="{{ settings.search_icon | img_url: '20x' }}" alt="Search" />
      {% endif %}
    </button>
  </form>

{% else %}
  {% if search.performed %}
    {% paginate search.results by 16 %}

    <h4 class="title">{{ 'search.general.heading' | t: count: search.results_count }}: {{ 'search.general.results_with_count' | t: terms: search.terms, count: search.results_count }}</h4>

    <div class="cata-product cp-grid">
      {% for product in search.results %}
        {% if product.object_type == 'product' %}
          <div class="product-grid-item">
            {% include 'product-item' %}
          </div>
        {% else %}
          <div class="article-grid-item">
            {% include 'article-result' %}
          </div>
        {% endif %}
      {% endfor %}
    </div>

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

    {% endpaginate %}
  {% endif %}

{% endif %}

如何编辑它以仅在与“已使用”匹配的集合名称中搜索?

有一个shopify collection object,但不知道我是否应该尝试编辑:

&lt;input type="text" name="q" class="search_box" placeholder="{{settings.search_placeholder}}" value="{{ search.terms }}" /&gt;

或搜索结果

{% for product in search.results %}

任何帮助将不胜感激,谢谢

【问题讨论】:

  • 您无法在 Shopify 上搜索产品系列,您只能搜索文章、页面和产品。
  • 如果你真的需要这个,那就在APP store里找任何APP。

标签: javascript shopify shopify-template


【解决方案1】:

获取所有结果,过滤,生成;问题是分页,我暂时没有解决方案。

{% paginate search.results by search.results_count %}
  {% for item in search.results %}
    {% if item.object_type == 'product' %}
      {% for collection in item.collections %}
        {% if collection.title contains 'myCollectionTitle' %}
          {% assign image = item.featured_image | img_url: 'medium' %}
          
          <a href="{{item.url}}">{{item.title}} <img src="{{image}}" alt="" class="" loading="lazy" width="" height=""></a><br>
          {% endif %}
      {% endfor %}
    {% endif %}
  {% endfor %}  
{% endpaginate %}

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2016-10-26
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多