我试图修改一个Shopify主题,该主题通过循环遍历集合来显示产品。我想在剩下的部分之后显示缺货产品,所以我创建了一个for循环来迭代库存项,然后再创建另一个循环来遍历缺货项。然而,总有一个股票上市,出现在所有的缺货上市后。
为了调试这一点,我在产品列表中以及液体循环前后添加了html标记。
上市公司怎么会有“有用”的评论,而在“最终可用产品”评论之后呢?
红色:可用产品
蓝色:不可用的产品

<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>发布于 2019-10-01 19:23:23
这个问题是因为在库存/缺货循环生成html后,改变了产品列表的顺序。解决此问题需要更改分页方法。
https://stackoverflow.com/questions/58142041
复制相似问题