shopify - 基于分组标签的相关产品会限制内存。使用带有特定句柄标签的集合
问题描述
从这一点开始https://www.shopify.com/partners/blog/related-products 我最终得到了这个自定义和工作代码:
{% comment %}
Get dynamic tag from product and create static collection handle
{% endcomment %}
{% for tag in product.tags %}
{% if tag contains 'IDSeries_' %}
{% assign ser_tag = tag %}
<li>
<a href="/collections/all/{{ ser_tag | handleize }}">
<h2>{{ ser_tag | remove: "IDSeries_" | prepend: "Go to products with Serie ID number:" }}</h2>
</a>
</li>
{% endif %}
{% endfor %}
{% comment %}
Return products by using the extracted tag
{% endcomment %}
{% for product in collections.all.products %}
{% if product.tags contains ser_tag %}
{{ product.title }}
{% endif %}
{% endfor %}
上面这个确实有效。但这不是解决方案!
由于内存有限,它仅适用于第一批产品,而不适用于所有产品。
- 考虑到我有25,000个产品都带有增量“IDSeries_'INT'”
- 我的目标是:展示具有相同特定“IDSeries_'INT'”的产品。
- 因为当这已经发生在这样的集合标签网址时
<a href="/collections/all/{{ ser_tag | handleize }}">
- 我想知道我是否可以
return
将已经在集合句柄标签 url 层过滤的产品(进入部分产品)。
所以在 Themes/Debut/Sections/product-template.liquid
我尝试以下没有运气:
{% assign collection_handle = ser_tag %}
{% for product in collections.all[collection_handle].products %}
{{ product.title }}
{% endfor %}
问题:
关于如何为如此大量的产品实现一致的结果的任何线索?
额外的问题:
- 对于一家拥有 30k 个产品的商店,每个产品有 5 个标签(总共 150k 个标签)。
- 标签有限制吗?
我还创建了一个 Shopify 社区主题https://community.shopify.com/c/Technical-QA/Related-products-based-on-grouping-tags-limit-memory-Use-instead/td-p/759705
解决方案
我可以为您的问题想出两种解决方案,这不会影响网站的速度。
基于搜索 + Javascript
Shopify 上的搜索页面也可以搜索标签。
因此,如果您向搜索页面发出 fetch 请求,如下所示:
fetch('/search?q=IDSeries_*').then(res => res).then(res => console.log(res))
这将返回包含此标签组合的产品,您可以使用 javascript 附加它。
因此,您将使用 javascript 填充产品。
GraphQL
您可以使用 Storefront GraphQL API 发出请求并按特定标签获取产品,如下所示:
{
products(first: 10, query:"tag:>'IDSeries_'"){
edges {
cursor
node {
title
}
}
}
}
这需要了解 GraphQL,尤其是他们的 Store-Front API(不是 Admin API)。
对于一家拥有 30k 个产品的商店,每个产品有 5 个标签(总共 150k 个标签)。
标签有限制吗?
集合的all_tags
对象最多可以返回 1000 个标签,其余的将被跳过。它们需要是唯一的标签,可重复的标签不算数。
除此之外,我的知识没有限制。
推荐阅读
- angular - 重定向到另一个页面Angular 7后如何重新加载主要组件
- python - 将函数转换为 Python 类
- javascript - 未捕获的类型错误:TransportU2F.create 不是函数
- javascript - 使用 javascript 在多选下拉列表中动态填充所选选项
- gradle - 不知道为什么doFirst()和doLst()没有执行
- flutter - 比将回调函数传递给子 Widget 更好的架构
- c# - 如何在c#中将两个数据源绑定到数据网格中
- javascript - 没有表单标签的复选框,没有找到选中的复选框
- r - 在 R 中按组自定义归一化
- react-native - Redux 未连接到 React Navigation 中的所有堆栈