Shopify Liquid:连续循环乱序迭代
Shopify Liquid: Consecutive for loops iterating out of order
我正在尝试修改一个通过循环遍历集合来显示产品的 Shopify 主题。我想在其余产品之后显示缺货产品,因此我创建了一个 for 循环来遍历有货商品,然后创建另一个循环来遍历缺货商品。但是,在所有缺货的listing之后总会出现一个有货的listing。
为了对此进行调试,我在产品列表中以及液体循环前后添加了 html 标签。
listing怎么会有“available”评论但是在“END Available Products”评论之后?
Red: Available Products
Blue: Unavailable Products
<div id="product-loop" {% if settings.collection-sidebar %}class="desktop-10 tablet-5 mobile-3"{% endif %}>
{% assign products-per-row = settings.products-per-row %}
<!-- Available Products -->
{% for product in collection.products %}
{% assign outofstock = true %}
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
{% assign outofstock = false %}
{% endif %}
{% endfor %}
{% if outofstock == false %}
{% if current_tags != null %}
<!-- Tag section removed for brevity -->
{% endif %}
<div class="product-index {% if template == 'index' and settings.homepage-product-display == 'carousel' %}{% else %}{% if products-per-row == "6" %}desktop-2{% cycle ' first', '', '', '', '', ' last' %}{% elsif products-per-row == "4" %}desktop-3{% cycle ' first', '', '', ' last' %}{% elsif products-per-row == "3" %}desktop-4{% cycle ' first', '', ' last' %}{% elsif products-per-row == "5" %}desktop-fifth{% cycle ' first', '', '', '', ' last' %}{% elsif products-per-row == "2" %}desktop-6{% cycle ' first', ' last' %}{% endif %} tablet-half mobile-half{% endif %}" data-alpha="{{ product.title }}" data-price="{{ product.price }}">
<!-- avail -->
{% include 'product-listing' %}
{% include "panda-swatch" %}
</div>
{% endif %}
{% endfor %}
<!-- END Available Products -->
<!-- Unavailable Products -->
{% for product in collection.products %}
{% assign outofstock = true %}
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
{% assign outofstock = false %}
{% endif %}
{% endfor %}
{% if outofstock == true %}
{% if current_tags != null %}
<!-- Tag section removed for brevity -->
{% endif %}
<div class="product-index {% if template == 'index' and settings.homepage-product-display == 'carousel' %}{% else %}{% if products-per-row == "6" %}desktop-2{% cycle ' first', '', '', '', '', ' last' %}{% elsif products-per-row == "4" %}desktop-3{% cycle ' first', '', '', ' last' %}{% elsif products-per-row == "3" %}desktop-4{% cycle ' first', '', ' last' %}{% elsif products-per-row == "5" %}desktop-fifth{% cycle ' first', '', '', '', ' last' %}{% elsif products-per-row == "2" %}desktop-6{% cycle ' first', ' last' %}{% endif %} tablet-half mobile-half{% endif %}" data-alpha="{{ product.title }}" data-price="{{ product.price }}">
<!-- no avail -->
{% include 'product-listing' %}
{% include "panda-swatch" %}
</div>
{% endif %}
{% endfor %}
<!-- END Unavailable Products -->
</div>
问题是由于分页改变了产品列表的顺序在 有货/缺货循环生成 html 之后。解决此问题需要更改分页方法。
我正在尝试修改一个通过循环遍历集合来显示产品的 Shopify 主题。我想在其余产品之后显示缺货产品,因此我创建了一个 for 循环来遍历有货商品,然后创建另一个循环来遍历缺货商品。但是,在所有缺货的listing之后总会出现一个有货的listing。
为了对此进行调试,我在产品列表中以及液体循环前后添加了 html 标签。
listing怎么会有“available”评论但是在“END Available Products”评论之后?
Red: Available Products
Blue: Unavailable Products
<div id="product-loop" {% if settings.collection-sidebar %}class="desktop-10 tablet-5 mobile-3"{% endif %}>
{% assign products-per-row = settings.products-per-row %}
<!-- Available Products -->
{% for product in collection.products %}
{% assign outofstock = true %}
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
{% assign outofstock = false %}
{% endif %}
{% endfor %}
{% if outofstock == false %}
{% if current_tags != null %}
<!-- Tag section removed for brevity -->
{% endif %}
<div class="product-index {% if template == 'index' and settings.homepage-product-display == 'carousel' %}{% else %}{% if products-per-row == "6" %}desktop-2{% cycle ' first', '', '', '', '', ' last' %}{% elsif products-per-row == "4" %}desktop-3{% cycle ' first', '', '', ' last' %}{% elsif products-per-row == "3" %}desktop-4{% cycle ' first', '', ' last' %}{% elsif products-per-row == "5" %}desktop-fifth{% cycle ' first', '', '', '', ' last' %}{% elsif products-per-row == "2" %}desktop-6{% cycle ' first', ' last' %}{% endif %} tablet-half mobile-half{% endif %}" data-alpha="{{ product.title }}" data-price="{{ product.price }}">
<!-- avail -->
{% include 'product-listing' %}
{% include "panda-swatch" %}
</div>
{% endif %}
{% endfor %}
<!-- END Available Products -->
<!-- Unavailable Products -->
{% for product in collection.products %}
{% assign outofstock = true %}
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
{% assign outofstock = false %}
{% endif %}
{% endfor %}
{% if outofstock == true %}
{% if current_tags != null %}
<!-- Tag section removed for brevity -->
{% endif %}
<div class="product-index {% if template == 'index' and settings.homepage-product-display == 'carousel' %}{% else %}{% if products-per-row == "6" %}desktop-2{% cycle ' first', '', '', '', '', ' last' %}{% elsif products-per-row == "4" %}desktop-3{% cycle ' first', '', '', ' last' %}{% elsif products-per-row == "3" %}desktop-4{% cycle ' first', '', ' last' %}{% elsif products-per-row == "5" %}desktop-fifth{% cycle ' first', '', '', '', ' last' %}{% elsif products-per-row == "2" %}desktop-6{% cycle ' first', ' last' %}{% endif %} tablet-half mobile-half{% endif %}" data-alpha="{{ product.title }}" data-price="{{ product.price }}">
<!-- no avail -->
{% include 'product-listing' %}
{% include "panda-swatch" %}
</div>
{% endif %}
{% endfor %}
<!-- END Unavailable Products -->
</div>
问题是由于分页改变了产品列表的顺序在 有货/缺货循环生成 html 之后。解决此问题需要更改分页方法。