我希望能够检查我在用户会话中设置的变量,并根据该变量使用户购物车免税。我怎样才能做到这一点?
我认为弄乱客户类型会变得太复杂。有没有其他方法来改变所适用的税收?或者随时改变客户群。
答案 0 :(得分:3)
我做了类似于此的事情,我已经将app / code / core / Mage / Tax / Model / Calculation.php覆盖为app / code / local / Mage / Tax / Model / Calculation.php并添加根据会话值将评级设置为0的评论下方显示的语句。这是在结账时动态计算的。
public function getRate($request)
{
if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
return 0;
}
$cacheKey = "{$request->getProductClassId()}|{$request->getCustomerClassId()}|{$request->getCountryId()}|{$request->getRegionId()}|{$request->getPostcode()}";
if (!isset($this->_rateCache[$cacheKey])) {
$this->unsRateValue();
$this->unsCalculationProcess();
$this->unsEventModuleId();
Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$this));
if (!$this->hasRateValue()) {
$this->setCalculationProcess($this->_getResource()->getCalculationProcess($request));
$this->setRateValue($this->_getResource()->getRate($request));
} else {
$this->setCalculationProcess($this->_formCalculationProcess());
}
$this->_rateCache[$cacheKey] = $this->getRateValue();
$this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
}
//this is the bit you're looking for down here
if (Mage::getStoreConfig('tax/calculation/calc_rate_zero')) {
$_taxvat = Mage::getSingleton('checkout/session')->getQuote()->getCustomerTaxvat();
if ( $_taxvat != null && $_taxvat != ' ') {
$this->setRateValue( 0 );
$this->_rateCache[$cacheKey] = $this->getrateValue();
$this->_rateCalculationProcess[$cacheKey]= $this->getCalculationProcess();
}
}
return $this->_rateCache[$cacheKey];
}