Register with your Envato account

Support forums

Homepage Support Polaris Shopify Update tax total line on cart.liquid of update of quantities

Update tax total line on cart.liquid of update of quantities

Homepage Support Polaris Shopify Update tax total line on cart.liquid of update of quantities

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #7329
    leahprin
    Participant

    I’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!

    #7332

    Hey,

    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.

Viewing 2 posts - 1 through 2 (of 2 total)
You must have active support license to create new replies.

Learn more about Renewing Item Support and Themeforest Item Support Policy.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close