Shopify产品页面上的库存显示输出

时间:2018-04-13 10:19:34

标签: shopify shopify-template

我花了很多时间建立一个新的shopify网站 - 我第一次体验shopify。其中大部分都非常直接,但在产品页面上显示库存时,我发现自己有点难过。我正在使用首次亮相主题,并使用编辑器更新'product-template.liquid'

浏览文档后,我添加了以下内容;

{% 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 for next-day delivery when you order by 2pm.
          {% else %}
             Out of Stock
          {% endif %}
        </div>

但是,目前这种物品实际上已经退货“缺货”。另外,我希望实现但未能找到文档的是

  • '库存商品'=我们有{{current_variant.inventory_quantity}}库存,以便您在下午2点之前订购,以便第二天发货。
  • '没有库存,但客户可以订购'=现在订购,可在7天内发货
  • '没有库存,客户不允许订购'=缺货

任何指针都非常赞赏!

2 个答案:

答案 0 :(得分:1)

你有:

          {% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
      We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
      {% else %}
         Out of Stock
      {% endif %}

这将显示&#39; Out-of-Stock&#39;以下任一条件的消息:

  • inventory_managementblank(这是默认值)
  • inventory_policycontinue

你可能想要的是这样的:

    {% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}

          {% comment %}
          We care about inventory on this product - is there any in stock?
          {% endcomment %}
          (% if current_variant.inventory_quantity > 0 %}
             We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
          {% else %}
             Out of Stock
          {% endif %}

    {% else %}
        {% comment %}
        Any code/messages we might want for products where we don't care about inventory
        {% endcomment %}
    {% endif %}

答案 1 :(得分:0)

我对这行代码感到有些困惑:

  

{%if current_variant.inventory_management ==“shopify”and current_variant.inventory_policy!=“continue”%}

您正在检查的是,如果您使用shopify来跟踪库存,并且在管理面板中检查了变量选项命令以允许人们订购,即使缺货也是如此。我会假设后者被检查所以它总是返回其他。

如果没有库存,则由于这一行没有显示任何内容:

  

div id =“variant-inventory”class =“{%除非current_variant.available%}隐藏{%endunless%}”&gt;

由于我不确定您计划如何区分缺货和缺货可以在7天内订购。由于库存跟踪器中没有任何内容允许您输入传入的产品(据我所知)。如果你打算手动输入,你可以去product.template.liquid找到 Ctrl + F

  

{%除非current_variant.available%}

第二个是销售代码发生的地方  并通过添加和删除标签来编辑它(使用noOrder和noStockCanOrder作为示例标签)

{% if product.tags contains 'noOrder' %}
  <div>No inventory, customer not allowed to order' = Out of Stock</div>
  -Insert Current out of stock code here-
{% elsif product.tags contains 'noStockCanOrder' %}
  <div>No inventory, but customer allowed to order' = Order now for delivery within 7 days</div>
  -Insert Current in stock code here-
{% else %}
  <div>Items in stock' = We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.</div>
    -Insert Current in stock code here-
{% endif %}

你可能不得不玩这个,因为我从来没有完全按照你的要求做,但理论应该是合理的,它应该让你接近你想要的东西,你可以从那里编辑它。

相关问题