Suneth Kalhara
Suneth Kalhara

Reputation: 1208

Magento 1.9 remove tax on checkout when user enter VAT

I'm trying to make magento modification when user enter vat number on checkout remove tax from order.

I found a code on stackoverflow which support on magento older version but it not work with new version 1.9,

I made few modifications for work the condition and return 0,even it return 0 checkout still shows tax.

here is my code which is on file

/app/code/core/Mage/Tax/Model/Calculation.php line number 268



    public function getRate($request)
        {
            if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
                return 0;
            } 


           //my code
            $ctax= Mage::getSingleton('checkout/session')->getQuote()->getCustomerTaxvat();


            if ($this->getCustomer() && $ctax !='') {
                //echo 'test';
                return 0;          
            }
        //end my code   


            $cacheKey = $this->_getRequestCacheKey($request);
            if (!isset($this->_rateCache[$cacheKey])) {
                $this->unsRateValue();
                $this->unsCalculationProcess();
                $this->unsEventModuleId();
                Mage::dispatchEvent('tax_rate_data_fetch', array(
                    'request' => $request));
                if (!$this->hasRateValue()) {
                    $rateInfo = $this->_getResource()->getRateInfo($request);
                    $this->setCalculationProcess($rateInfo['process']);
                    $this->setRateValue($rateInfo['value']);
                } else {
                    $this->setCalculationProcess($this->_formCalculationProcess());
                }
                $this->_rateCache[$cacheKey] = $this->getRateValue();
                $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
            }
            return $this->_rateCache[$cacheKey];
        }

Anyone can help me to make tax 0 when user enters vat number on checkout, Thanks a lot

Upvotes: 1

Views: 2990

Answers (3)

Crock
Crock

Reputation: 163

Go to Calculation.php and find the calcTaxAmount() and add billing condditions

public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
    {
          $billing = Mage::getModel('checkout/session')->getQuote()->getCustomerTaxvat();
        if($billing !="")
         {
           return 0;
         }
    }

Upvotes: 0

faizanbeg
faizanbeg

Reputation: 391

I've managed to solve my problem by following this thread : Modify tax rate on cart quote items and recalculate

I have added an Observer to the event sales_quote_collect_totals_before.

And here is the content of my observer, very simple :

    public function removetax($observer)
    {
        $customer_id = Mage::getSingleton('customer/session')->getId();
        $customer = Mage::getModel("customer/customer")->load($customer_id);

        if($customer->getIsTaxExempt() == 1)
        {
            $items = $observer->getEvent()->getQuote()->getAllVisibleItems();
            foreach($items as $item)
                $item->getProduct()->setTaxClassId(0);
        }
    }

If customer is tax exempt, I grab the current cart content and for each item, I set the product tax class to 0. It is mandatory to not save the product or the item. The aim here is to set a value for the following calculation, not to save it in the database. Tax classes need to stay to the initial value in the db.

Upvotes: 4

Hardik Visa
Hardik Visa

Reputation: 323

You can use sales_quote_collect_totals_before event.

then you have to define logic for remove tax on checkout page.

This link you can refer.

Upvotes: 0

Related Questions