Magento – Tax rate on cart page

carttax

I need to display the tax rate (varies with different countries) next to shipping text on cart page. How could I print the tax rate used in template php file?

Best Answer

If I understand you correctly you want to highlight what taxes are applied on cart totals.

What configuration did you have setup System>Configuration>Sales>Tax

Shopping Cart Display Settings and option:

Include Tax In Grand Total [STORE VIEW] Yes
Display Full Tax Summary [STORE VIEW] Yes

The name that's being displayed in frontend cart totals, are in Sales>Tax>Manage Tax Zone & Rates, then you edit the rate and at the bottom there are Tax Titles for each Store View.

If i understand you in a bad way - then do you want to display tax rate for shipping cost on estimated shipping cost block?

EDIT: Shipping cost tax percentage on cart page

This is kind of a hack, but I think you'll get an idea behind it and you can do whatever you want with it.

Go to /template/checkout/cart/shipping_method/available.html

Find around line ~59:

<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>

Above you can see how's shipping method cost is displayed on frontend. Try to add for testing purposes code like this:

<?php echo $excluding = (float)preg_replace('/\D/', '', $_excl)/100; ?>         
<?php echo $including = (float)preg_replace('/\D/', '', $_incl)/100; ?>         
<?php $taxamount=$including-$excluding;
      $taxPercentage = ($taxamount / 100) * $including;
      $percent = $taxamount/$excluding;
      echo $percent_friendly = number_format( $percent * 100, 2 ) . '%';
?>

Now above the variable $excluding gets estimated shipping cost without tax amount and converts it to float number format. Same goes for $including.

Then we subtract $excluding from $including and we have variable $taxamount which's the tax amount in number format. The rest is obvious I think.

I hope you'll find a better way to implement this solution – it's simplest, baddest hack in template file.

Related Topic