getQuote不在某些商店工作

时间:2017-02-17 04:49:56

标签: php magento-1.9 checkout tax

我需要限制税额。所以我去了Mage/Tax/Model/Calculation.php 然后查找 calcTaxAmount() 税务申请功能。 我需要限制所有人都在结账时纳税的税收一页税应为零 所以

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 这个问题。我删除新的条件,如下工作正常。

旧功能: -

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

2 个答案:

答案 0 :(得分: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;
    }

答案 1 :(得分:0)

我被固定在流下: -

而不是在Calculation.php中使用GetQuote使用会话变量

  

<强>法/结帐/型号/类型/ Onepage.php

功能名称: - 公共功能saveBilling($ data,$ customerAddressId)

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

return array(); 之前的onepage.php中添加以上代码,这意味着最后一个功能。

现在接下来获取会话变量

  

法/税务/型号/ 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;
    }