2017-12-08 8 views
0

にdiferent合計を表示するために、私はitemquantityに基づいてcart上の異なるpricesを示しています、cartitemitem.quantity以上6を持っている場合、それはmetafieldに保存されてpriceをカウントする必要があり、それ以外の場合はdefault priceと表示されます。このことを知って、私はサポートされていないか、私が使用していsubtotal += valueをやって見てきたように例どのようにカートshopify

//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 %} 

そして最後のものprices、に基づいてcarttotalが小計に

{{ 'general.cart_info.sub_total' | t }}<span><span class="amount">{{ subtotal | money }}</span></span> 

を表示表示したいですそれは間違っている、これを行う方法はありますか?

編集

私は隠された入力とこの

//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); 
} 

この作品のようなJS関数を使用して回避策をしましたが、それは私が行うことができるはず、それを行うための最善の方法ではありませんそれはサーバー側のものです。何かアドバイス?

+0

assignを使うのか? – HymnZ

答えて

0

フム、どれだけあなたがチェックアウトするために、この調整値を渡す予定ですか再び

{% 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 %} 
関連する問題