如何在shopify的相关项目部分中获取随机产品?

时间:2019-04-02 10:10:51

标签: jquery liquid

我要在网站上设置一个新部分,当在产品下面选择一个产品时,我的部分显示了相同品牌的产品,现在我有150多个具有相同品牌的产品,但是我只显示5个,我想显示每次加载页面时,都会随机抽取5个具有相同品牌的产品,我该如何实现?

 {% assign collection_title = collection.handle %}
 {% assign vendor = product.vendor %}
 {% assign product_handle = product.handle %}

 {% assign counter = '' %}
 {% assign relatedCollection = collections['all'].all_products %}
 {% assign index = 'now' | date: '%S' %}
 {% assign index = index | times: relatedCollection.products.size %}
 {% assign index = index | divided_by: 60 %}

 {% for product in collections['all'].all_products offset: index %}
   {% if vendor == product.vendor and counter.size < 5 and product_handle 
   != product.handle %}
   {% capture temp %}{{ counter }}*{% endcapture %}
   {% assign counter = temp %}
   {% include 'product-grid-item' %}
   {% endif %} 
{% endfor %}

0 个答案:

没有答案