基于分组标记的相关产品会限制内存.请改用带有特定句柄标签的集合

  • 本文关键字:内存 标签 句柄 集合 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 %}

以上确实有效。但这不是解决方案!
由于内存有限,它仅适用于第一批产品,而不适用于所有产品。

  • 考虑到我有两万五千种产品,所有产品都有一个增量"IDSeries_'INT'
  • "
  • 我的目标是:展示具有相同特定"IDSeries_'INT'"的产品。
  • 因为当这已经发生在像这样的收集标签 url 上时<a href="/collections/all/{{ ser_tag | handleize }}">
  • 我想知道我是否可以return已经在集合句柄标签 url 层过滤的产品(到部分产品中(。

因此,在主题/首次亮相/部分/产品模板.liquid
中,我正在尝试以下内容,但没有运气

{% assign collection_handle = ser_tag %}
{% for product in collections.all[collection_handle].products %}
{{ product.title }}
{% endfor %}

问题:
关于如何为如此大的产品库存实现一致的结果,有什么线索吗?

额外问题:

  • 对于具有 30k 产品的商店,每个产品有五个标签(因此 150k 标签在 总计(。
  • 标签有什么限制吗?



我还创建了一个 Shopify 社区主题 https://community.shopify.com/c/Technical-Q-A/Related-products-based-on-grouping-tags-limit-memory-Use-instead/td-p/759705

我可以为您的问题想到两种解决方案,这不会影响网站的速度。

基于搜索 + Javascript

搜索页面 Shopify 也可以搜索标签。

因此,如果您像这样向搜索页面发出抓取请求:

fetch('/search?q=IDSeries_*').then(res => res).then(res => console.log(res))

这将返回包含此标签组合的产品,您可以将其与 javascript 一起附加。

因此,您将使用javascript填充产品。

图QL

您可以使用 Storefront GraphQL API 发出请求并按特定标签获取产品,如下所示:

{
products(first: 10, query:"tag:>'IDSeries_'"){
edges {
cursor
node {
title
}
}
}
}

这需要了解 GraphQL,尤其是他们的 Store-Front API(而不是 Admin API(。


对于拥有 30k 产品的商店,每个产品带有五个标签(因此总共 150k 个标签(。

标签有什么限制吗?

集合的all_tags对象最多可以返回 1000 个标记,其余的将被跳过。它们必须是唯一的标签,可重复的标签不算在内。

除此之外,我的知识没有任何限制。

因此,在一天结束时,将标签搜索结果显示在 Shopify 我使用fetch()的部分,脚本如下所示:

<script>  
{% for tag in product.tags %}
{% if tag contains 'IDSeries_' %}
{% assign ser_tag = tag %}
{% endif %}
{% endfor %}
const url = '/search?view=serie_list&q={{ ser_tag }}';  
fetch(url)
.then(response => response.text( 
))
.then(data => {
$('#serie_list_id').html(data);
});
</script>

同样,正如魔术@drip所说,我创建了一个单独的搜索模板,顶部有{% layout none %}和其他样式

最新更新