How to Modify Magento TAX Calculation



In this tutorial I will explain how you can modify magento TAX calculation. Sometimes we need to modify the magento tax calculation according to your requirement for specific products or categories.

To modify in Tax Calculation get a copy of the file code\core\Mage\Tax\Model\Calculation.php into community as app\code\community\Mage\Tax\Model\Calculation.php. Now find calcTaxAmount function on line no 600.

Now change in this function as per your requirement and create a log table to store and trace.

public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
	$taxRate = 15;
	$taxRate = $taxRate/100;
	$this->insertInLog('taxRate', $taxRate);
	$this->insertInLog('price', $price);
	
	if ($priceIncludeTax) {
		$amount = $price*(1-1/(1+$taxRate));
	} else {
		$amount = $price*$taxRate;
	}
	
	$this->insertInLog('Amount', $amount);
	if ($round) {
		return $this->round($amount);
	} else {
		return $amount;
	}
}

/**
 * Insert in to Log Table to trace.
 *
 * @param   varchar $field
 * @param   varchar $val
 */

function insertInLog($field, $val){
	mysql_connect("localhost", "root","");
	mysql_select_db("magentolog");
	
	$sql = "insert into mage_log_tbl values('".$field."', '".$val."', '".date("Y-m-d h:i:s")."')";
	mysql_query($sql);
}

Hope this tutorial will help you to change in tax calculation.