Homepage › Support › Polaris Shopify › Update tax total line on cart.liquid of update of quantities
- This topic has 1 reply, 2 voices, and was last updated 4 years, 9 months ago by
Planetshine Support.
-
AuthorPosts
-
August 15, 2017 at 2:51 am #7329
leahprin
ParticipantI’ve added a tax total line on the cart.liquid page with:
<div class="total-label">GST:</div> <div class="total-value-gst">{{ cart.total_price | times: 0.10 | money }}</div>
I’ve changed the class for the value to .total-value-gst to ensure that on update of quantities, the JS doesn’t override it to the total price. Inside of polaris.js I can see:
initCartTotalPriceUpdate: function (total_price) { var cart_form = jQuery('form.cart'); var total_varies = cart_form.attr('data-total-varies'); var new_price; if (total_varies == 'true') { var compare_price = 0; jQuery('.cart-items form').each(function () { compare_price += parseInt(jQuery(this).attr('data-line-price-compare')); }); new_price = "<span>" + Shopify.formatMoney(total_price, window._money_format) + "<s>" + Shopify.formatMoney(compare_price, window._money_format) + "</s></span>"; } else { new_price = Shopify.formatMoney(total_price, window._money_format); } cart_form.find('.total-value').html(new_price); },
… which is the function I think that updates the price on qty update. How can I modify it to also update the GST/tax (it’s always 10% of the total price).
I realise this is out of scope of normal support, so any hints you had like last time would be much appreciated. Thank you!
August 15, 2017 at 3:34 pm #7332Planetshine Support
KeymasterHey,
As far I understood you prefer to update not only tax value but also add tax to the total value dynamically on any change in cart. You should update “initCartTotalPriceUpdate” in this way:
initCartTotalPriceUpdate: function (total_price) { var cart_form = jQuery('form.cart'); var total_varies = cart_form.attr('data-total-varies'); var new_price; var tax; if (total_varies == 'true') { var compare_price = 0; jQuery('.cart-items form').each(function () { compare_price += parseInt(jQuery(this).attr('data-line-price-compare')); }); tax = Math.round(compare_price * 0.1); compare_price += tax; new_price = "<span>" + Shopify.formatMoney(total_price, window._money_format) + "<s>" + Shopify.formatMoney(compare_price, window._money_format) + "</s></span>"; } else { tax = Math.round(total_price * 0.1); new_price = Shopify.formatMoney((total_price + tax), window._money_format); } cart_form.find('.total-value-gst').html(tax); cart_form.find('.total-value').html(new_price); },
Probably this code requires some improvement as it hasn’t been tested.
-
AuthorPosts
Learn more about Renewing Item Support and Themeforest Item Support Policy.