简体   繁体   中英

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

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.

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.

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;
         }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM