getQuote 不适用于某些商店

getQuote not working some stores

我需要限制税额。所以我去了 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;
    }

试试下面的代码希望这有帮助。

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

我被固定在流程以下:-

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

Mage/Checkout/Model/Type/Onepage.php

函数名称:- public function saveBilling($data, $customerAddressId)

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

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

下面获取访问会话变量

Mage/Tax/Model/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;
    }