Shopify - 从特定 collection 获取产品列表

Shopify - Get list of product from a specific collection

在 shopify 中,我创建了 4 个下拉菜单。

下拉列表 1 - 城市 下拉菜单 2 - 商店类别(如服装、文具等) 下拉列表 3 - 特定城市和特定商店的商店 下拉列表 4 - 特定商店可用的商品

我的要求是,当在下拉列表下方选择特定商店(下拉列表 3)时,应列出该商店中的所有产品(我会将产品作为 collection 和 collection 的一部分名称将与店铺名称相同)。

我意识到我需要使用 Ajax。我检查了 shopify 提供的 API,但不知何故我无法连接点。我无法使用它。能否请您提供一个指针,其中解释了如何实现它。

请注意,我是网络开发和 shopify 的新手。

已编辑*

  1. 我创建了另一个名为 "collection.alternate" 的模板。
  2. 将 collection 标记到新模板。
  3. 在 theme.liquid 中,我使用了以下代码,以避免 header 和页脚在 iframe

    中显示

    {% 如果模板 != 'collection.alternate' %} {% 包括 'header-bar' %} ..... {% endif %}

  4. 使用 iframe 加载 collection.alternate。

但是在 iframe 中 Header 仍然显示。当我在 Chrome 开发人员工具中分析 iframe 的 "Elements" 时,我看到 header 逻辑是为 collection.template 生成的。如何阻止 header 出现在 iframe 中。

要调用 shopify 收集的产品,您只需使用此循环即可:

{% for product in collections.shop_name.products limit: 4 %}     /*********** shop_name is collections name limit is used to show no. of products ******/
       <li><a href="{{ product.url}}"><img src="{{ product.featured_image | product_img_url: 'medium' }}" alt=""></a></li>
 {% endfor %}

此功能不需要 AJAX。

四个下拉列表中的每个值都应作为标签添加到产品中。然后您可以使用简单的 JavaScript 命令根据需要更改 url 并显示所需的产品。

例如,假设您将纽约作为 城市,将 CK 作为 商店。现在要展示在纽约CK门店的产品,所有上述产品都必须包含纽约和CK作为标签。显示上述产品的最终 URL 将是 - storename.myshopify.com/collections/all/new-york+ck

下面是 link to shopify 文章,描述了如何根据标签筛选产品。

https://docs.shopify.com/support/your-store/collections/filtering-a-collection-with-multiple-tag-drop-down

感谢@Hymnz 指导我阅读这篇文章。

只需在 collection 数组索引

中提及您的 collection 姓名
{% for product in collections['collection-name'].products %}
{{product.name}}
{% endfor %}