当用户输入增值税时,Magento 1.9会在结帐时免除税款 [英] Magento 1.9 remove tax on checkout when user enter VAT
问题描述
当用户在结帐时输入增值税号时,我正在尝试进行magento修改.从订单中删除税款.
I'm trying to make magento modification when user enter vat number on checkout remove tax from order.
我在stackoverflow上找到了一个支持magento较旧版本的代码,但不适用于新版本1.9 ,
我对工作条件做了一些修改,并返回0,即使返回0结帐仍显示税金.
I made few modifications for work the condition and return 0,even it return 0 checkout still shows tax.
这是我的代码存档
/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,非常感谢
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
我已将观察者添加到事件sales_quote_collect_totals_before
.
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);
}
}
如果客户免税,则获取当前的购物车内容,并将每个商品的产品税类设置为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.
这篇关于当用户输入增值税时,Magento 1.9会在结帐时免除税款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!