2017-02-17 26 views
1

我需要限制稅額。所以我去了Mage/Tax/Model/Calculation.php 然後找到calcTaxAmount()稅務申請功能。 我需要限制稅務誰都是進入結賬稅收vatid onepage稅應該是零 所以getQuote無法正常工作

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

     if($billing != "") 
     { 
      return 0; 
     } 
     $taxRate = $taxRate/100; 

     if ($priceIncludeTax) { 
      $amount = $price * (1 - 1/(1 + $taxRate)); 
     } else { 
      $amount = $price * $taxRate; 
     } 

     if ($round) { 
      return $this->round($amount); 
     } 

     return $amount; 
    } 

我增加了新的條件。其工作的一些多層商店。只有一家商店無法正常工作。它會導致用戶無法註冊,並且addtocart不適用於該特定商店。我發現getQuote的問題。我刪除了像下面的新的condtion工作正常。

老功能: -

public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true) 
    { 
     $taxRate = $taxRate/100; 

     if ($priceIncludeTax) { 
      $amount = $price * (1 - 1/(1 + $taxRate)); 
     } else { 
      $amount = $price * $taxRate; 
     } 

     if ($round) { 
      return $this->round($amount); 
     } 

     return $amount; 
    } 

回答

0

我是固定以下流程: -

而是採用了getQuote在Calculation.php使用會話變量的

法師/結帳/型號/類型/ Onepage.php

函數名稱: - public function saveBilling($ data,$ customerAddressId)

 $assign = $this->getQuote()->getCustomerTaxvat(); 
     if ($assign !="") 
     { 
      $this->_checkoutSession->setVatSession($assign); 
     } 
     else 
     { 
      $this->_checkoutSession->unsVatSession(); 
     } 

加入上面的代碼中onepage.php前return array();這意味着最後的功能。

現在下面獲取訪問會話變量

法師/稅務/型號/ Calculation.php

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

     if ($priceIncludeTax) { 
      $amount = $price * (1 - 1/(1 + $taxRate)); 
     } else { 
      $amount = $price * $taxRate; 
     } 

     if ($round) { 
      return $this->round($amount); 
     } 

     return $amount; 
    } 
1

試試下面的代碼希望這有助於。

public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true) 
    { 
     $currenQuoteId = Mage::getSingleton('checkout/session')->getQuoteId(); 
    $store = Mage::getSingleton('core/store')->load(Mage::app()->getStore()->getId()); 
      $quote = Mage::getModel('sales/quote')->setStore($store)->load($currenQuoteId); 
     $billing = $quote->getCustomerTaxvat(); 

     if($billing != "") 
     { 
      return 0; 
     } 
     $taxRate = $taxRate/100; 

     if ($priceIncludeTax) { 
      $amount = $price * (1 - 1/(1 + $taxRate)); 
     } else { 
      $amount = $price * $taxRate; 
     } 

     if ($round) { 
      return $this->round($amount); 
     } 

     return $amount; 
    } 
+0

感謝@ user247217。我是固定的。我添加了我的答案。 – Crock