如何在购物车上展示不同的总数

时间:2017-12-08 22:02:14

标签: javascript shopify liquid cart

如果prices中的cartquantity,我会根据item的{​​{1}}在item上显示不同的cart 6item.quantity以上price以上metafield保存default price,其他total显示cart。知道这一点我想基于那些prices//i declare a variable for the subtotal {% assign subtotal = 0 &} {% item.quantity >= 6 %} //if the item qty is greater than 6 i show a different prices, in this case a price saved on a metafield {% subtotal += item.product.metafields.global.wholesale_price | times:item.quantity %} {% else %} {% subtotal+= item.price | times:item.quantity %} {% endif %} 上显示{{ 'general.cart_info.sub_total' | t }}<span><span class="amount">{{ subtotal | money }}</span></span> ,例如

subtotal += value

最后显示小计

//on the liquid file i added the hidden field with a custom class with the sub-total of that row
{% for item in cart.items %}
    {% item.quantity >= 6 %}
        <input type="hidden" value="{{ price | times: item.quantity }}" class="subtotals">
    {% else %}
        <input type="hidden" value="{{ sca_price }}" class="subtotals">
    {% endif %}
{% endfor %}
//in the function i calculate de sum of all the rows and show the result on a div called show_subtotal
function calculateSubtotal()
{   
    var subtotal = parseInt(0);
    $('.subtotals').each(function(index, el) {
        subtotal += parseInt($(el).val());
    });
    subtotal = '$'+subtotal;
    subtotal = subtotal.slice(0,-2)+'.'+subtotal.slice(-2)
    $('.show_subtotal').html(subtotal);
}

正如我所看到的那样wd,ac=raw_input().split(" ") wd=int(wd) ac=float(ac) if(ac<wd): print(ac) elif(wd%5==0): if(ac>wd+0.50): print(ac-wd-0.50) else: print(ac) else: print(ac) 不受支持或我使用它错了,有没有办法做到这一点?

被修改

我使用隐藏输入和像这样的js函数做了一个解决方法

Runtime NZEC Error

这项工作,但它不是最好的方法,我应该能够在服务器端这样做。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

嗯,再次使用assign

{% assign subtotal = 0 &}
{% item.quantity >= 6 %}
    //if the item qty is greater than 6 i show a different prices, in this case a price saved on a metafield
    {% assign subtotal = item.product.metafields.global.wholesale_price | times: item.quantity %}
{% else %}
    {% assign subtotal =  item.price | times: item.quantity %}
{% endif %}