繁体   English   中英

当用户输入增值税时,Magento 1.9会在结帐时免税

[英]Magento 1.9 remove tax on checkout when user enter VAT

当用户在结帐时输入增值税号码时,我试图进行magento修改,以便从订单中删除税款。

我在stackoverflow上找到了支持magento较旧版本的代码,但不适用于新版本1.9

我对工作条件作了一些修改并返回0,即使返回0结帐仍然显示税款。

这是我的代码已存档

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

当用户在结帐时输入增值税号码时,任何人都可以帮助我将税款设为0,非常感谢

我设法通过遵循以下线程解决了我的问题: 修改购物车报价项目的税率并重新计算

我已经向事件sales_quote_collect_totals_before添加了一个Observer。

这是我的观察者的内容,非常简单:

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

如果客户免税,则获取当前的购物车内容,并为每个项目将产品税类设置为0。不保存产品或项目是强制性的。 此处的目的是为以下计算设置一个值,而不是将其保存在数据库中。 税种需要保持在数据库中的初始值。

您可以使用sales_quote_collect_totals_before事件。

那么您必须在结帐页面上定义删除tax逻辑。

您可以参考此链接

转到Calculation.php并找到calcTaxAmount()并添加计费条件

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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