So, for example, let's say I have a product with a price of $10 and special price of $0, I want to calculate the tax based on the $10 price and not the $0 special price. I can't seem to find any way in Magento to do this.

2 Answers 2


you can create your own function to calculate product price with

Here i can give you sample code

 $classId = $product->getTaxClassId();
 $this->_allTaxClass = $this->getAlltaxClass();
 $vat =    $this->_allTaxClass[$classId];

where $this->_allTaxClass wil be tax class in system which can be find like below

protected function getAlltaxClass() {
    // Get all tax classies and its percentage
    $allTaxClass = array();
    $taxClass = Mage::getModel('tax/class')->getCollection();
    $store = Mage::app()->getStore('default');
    $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
    foreach ($taxClass as $class) {
        $taxClassId = $class->getClassId();
        $allTaxClass[$taxClassId] = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
    return $allTaxClass;

then finally call

 $_price = number_format($objProduct->getPrice(), 2, ".", "");
 $price = $this->priceWithVat($_price, $this->_allTaxClass[$classId]);

where actual function to get price with Vat

     * get price with vat
     * @return  price including vat
     * */
    public function priceWithVat($price, $vat) {
        return $price + (($price * $vat) / 100);
  • Where should I add this bit of code? Feb 2, 2015 at 7:12
  • where you want this ? if in all pages then could be some module or helper
    – liyakat
    Feb 2, 2015 at 7:16
  • Sorry, I don't have high enough cred to upvote here yet, but thanks for your help! Feb 11, 2015 at 22:05
  • hello liyakat, Can i apply the tax on the price after some deduction from the product price? Example-i m using a subscription method if customer is subscribed than we deduct some amount from the price of product, i want to apply the tax on the (product_price - some_deduction) please help Oct 12, 2016 at 16:15
  • yes you can pass price after deduct your subscription
    – liyakat
    Oct 13, 2016 at 11:15

Here's what I ended up doing :

  • Created a product attribute called 'taxable_value' and set this to the taxable price.

  • Created a Magento extension and extended Mage_Sales_Model_Order_Invoice_Total_Abstract and Mage_Sales_Model_Quote_Address_Total_Abstract (extending these gave me the behavior I needed, not sure if this is the best approach)

  • I opted to treat taxable value as an additional tax (ie, an additional row in the totals array) so as to avoid Magento's tax behavior. This made it simple to get the numbers right, but the presentation can be rather wonky (concatenate values in Block models to suit).

  • Quick and dirty example:

    class BrainBytes_TaxableValue_Model_Sales_Order_Invoice_Total_Taxablevalue      extends Mage_Sales_Model_Order_Invoice_Total_Abstract
        public function collect(Mage_Sales_Model_Order_Invoice $invoice)
            // Get any amount we've invoiced already
            $prevInvoiceTaxableValueAmt     = 0;
            $prevInvoiceBaseTaxableValueAmt = 0;
            foreach ($invoice->getOrder()->getInvoiceCollection() as         $prevInvoice) {
                if ($prevInvoice->getTaxableValueAmount() && !$prevInvoice-        >isCanceled()) {
                    $prevInvoiceTaxableValueAmt += $prevInvoice-        >getTaxableValueAmount();
                    $prevInvoiceBaseTaxableValueAmt += $prevInvoice-        >getBaseTaxableValueAmount();
            $customSurchargeAmt  = 0;
            $baseTaxableValueAmt = 0;
            $invoiceIsLast       = true;
            foreach ($invoice->getAllItems() as $item) {
                $orderItem = $item->getOrderItem();
                if ($orderItem->isDummy()) {
                if (!$item->isLast()) {
                    $invoiceIsLast = false;
                $orderItemQty          = $orderItem->getQtyOrdered();
                $orderItemPrevInvoiced = $orderItem->getQtyInvoiced();
                if (($orderItemPrevInvoiced + $item->getQty()) ==         $orderItemQty) {
                    $customSurchargeAmt += $orderItem-        >getTaxableValueAmount();
                    $baseTaxableValueAmt += $orderItem-        >getBaseTaxableValueAmount();
            if ($invoiceIsLast) {
                $customSurchargeAmt  = $invoice->getOrder()->getTaxableValueAmount() - $prevInvoiceTaxableValueAmt;
                $baseTaxableValueAmt = $invoice->getOrder()->getBaseTaxableValueAmount() - $prevInvoiceBaseTaxableValueAmt;
            $invoice->setGrandTotal($invoice->getGrandTotal() +         $customSurchargeAmt);
            $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() +         $baseTaxableValueAmt);
            return $this;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.