2012-07-12 70 views
1

我希望能夠檢查我在用戶會話中設置的變量,並基於此使用戶購物車免稅。我怎樣才能做到這一點?根據會話條件免除結賬會話稅

我認爲搞亂客戶類型會太複雜。是否有另一種方法來改變應用的稅收?或者隨時更改客戶羣。

回答

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]; 
} 
+0

我試着添加這個作爲模塊重寫,它不會工作。我做到了,因爲你做到了,而且工作得很好。爲什麼模塊不能重載?你有什麼想法嗎? – Chris 2012-07-24 15:42:26

+0

@Chris請解釋你做了什麼來試圖覆蓋它。 – Sturm 2012-07-24 16:09:28

+0

我使用Models和etc文件夾創建了一個新模塊。我還將相應的配置文件添加到etc/modules。基本上我把它設置爲一個標準的自定義模塊。我使用這種機制來覆蓋其他幾個模型。 – Chris 2012-07-24 19:53:26