在具有属性的shopify中使用数学过滤器可以使0在硬编码值下正常工作

问题描述:

我已计算循环验证通过在输出中打印的值的总订单价格。下面提到的是相同的代码块:在具有属性的shopify中使用数学过滤器可以使0在硬编码值下正常工作

{% assign total_items_price = 0 %} 
    {% for line_item in line_items %} 
     {%assign total_items_price = total_items_price | plus:line_item.price %} 
    {% endfor %} 

以下是我已经实现了进一步的计算场景:试图划分每个项目的价格由total_items_price

  1. ,但输出0即使我将其转换成货币格式结果仍然相同:

    {{ line_item.price | divided_by:total_items_price }} 
    {{ line_item.price | divided_by:total_items_price | money }} 
    
      开始=“2”>
    1. 我已经使用多只要数学过滤器也可以结果为0:

      {{line_item.price | divided_by:total_items_price | times:discounts_amount}} {{line_item.price | divided_by:total_items_price |次:discounts_amount |钱}}的变量/属性(line_item.price,total_items_price,discounts_amount)

    值可用内部的for循环通过在UI印刷验证。如果我使用一些硬编码值而不是属性/变量,它会给出正确的输出。例如:

    {{ line_item.price | divided_by:5 }} //gives the correct output 
    

    也许你可以使用forloop.length值。由于在循环中没有任何条件语句,因此不需要手动索引。

    HTH

    您应该尝试在line_item.price上使用数学过滤器。

    {% assign total_items_price = 0 %} 
    {% for line_item in line_items %} 
        {% assign total_items_price = total_items_price | plus: line_item.price %} 
        {{ line_item.price | times: 1.0 | divided_by: total_items_price }} 
    {% endfor %} 
    

    通知了 “时间:1.0” 滤波器line_item.price后施加在线路4