我想随机化 Dawn Shopify 主题中特色系列中的订单产品。我在stakoverflow上看到相关产品有类似的解决方案:How to randomize related products in Shopify
您知道是否可以解决我的问题?你能帮我看一下代码吗?
我想这是适合的代码(但我不确定):
{%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
<li id="Slide-{{ section.id }}-{{ forloop.index }}" class="grid__item{% if show_mobile_slider or show_desktop_slider %} slider__slide{% endif %}">
{% render 'card-product',
card_product: product,
media_aspect_ratio: section.settings.image_ratio,
show_secondary_image: section.settings.show_secondary_image,
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating,
show_quick_add: section.settings.enable_quick_add,
section_id: section.id
%}
</li>
{%- else -%}
{%- for i in (1..4) -%}
<li class="grid__item">
{% render 'card-product', show_vendor: section.settings.show_vendor %}
</li>
{%- endfor -%}
{%- endfor -%}
您可以使用以下代码:
{%- assign paginate_index = limit | plus: 0 -%}
{% assign total_products = collection.products.size %}
{% assign start_index = "now" | date: "%L" | modulo: total_products %}
{% assign start_index1 = start_index | plus: 5 %}
{% if start_index1 >total_products %}
{% assign start_index = 1 %}
{% endif %}
{% assign products_shown = 0 %}
{% for product in collection.products %}
{% if forloop.index0 >= start_index %}
<!-- product display code -->
{% assign products_shown = products_shown | plus: 1 %}
{% if products_shown >= paginate_index %}{% break %}{% endif %}
{% endif %}
{% endfor %}