【问题标题】:shopify with multiple variants not showing the proper quantity. how to fixshopify 有多个变体没有显示正确的数量。怎么修
【发布时间】:2020-05-20 14:53:19
【问题描述】:

我有 shopify 显示正确的库存数量,但只有当我刷新每个变体的页面时。例如: 我有 12 个变体,数量从 1-8 不等,但如果我单击变体 1,它显示我有两个。如果我单击变体 6,它仍然显示我有 2,除非我单击刷新页面,然后它将显示正确的库存数量。我正在尝试解决此问题,因此当我更改变体时,价格和数量会同时更新,但不确定如何。你能帮帮我吗?

这是我正在使用的代码

{% comment %} Inventory tracking on product page {% endcomment %}
        <div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}">
          {% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
          We have {{ current_variant.inventory_quantity }} in stock.
          {% else %}
          This product is available.
          {% endif %}
        </div>

它在第 121 行: product-template.liquid

【问题讨论】:

    标签: css shopify liquid


    【解决方案1】:

    您的product-template.liquid 只会影响页面加载时可见的内容 - 它不是动态的,并且 Liquid 无法知道加载后页面上发生了哪些事件。

    为了实现您想要的,您需要一些客户端 JS 来观察选择的变体的变化,并分别更新副本。

    【讨论】:

    • 对不起,我忘了提到我在 JS 中使用脚本-我正在使用&lt;div id="variant-inventory"&gt; {% if product.variants.first.inventory_management == "shopify" %} {% if product.variants.first.inventory_quantity &gt; 0 %} We currently have {{ product.variants.first.inventory_quantity }} in stock. {% else %} The product is out of stock {% endif %} {% else %} This product is available {% endif %} &lt;/div&gt;
    • 它添加了这个产品缺货,然后当我刷新时,这个产品有库存然后它下面有数量,但只有在刷新时。我希望它没有添加,只是告诉数量而无需我刷新页面。它在 theme.js 的第 779 行
    猜你喜欢
    • 2020-06-20
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多