【问题标题】:getQuote not working some storesgetQuote 在某些商店不起作用
【发布时间】:2017-02-17 04:49:55
【问题描述】:

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

【问题讨论】:

    标签: php magento-1.9 checkout tax


    【解决方案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;
        }
    

    【讨论】:

    • 谢谢@user247217。我是固定的。我添加了我的答案。
    【解决方案2】:

    我被固定在流程之下:-

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

    Mage/Checkout/Model/Type/Onepage.php

    函数名称:- 公共函数 saveBilling($data, $customerAddressId)

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

    在onepage.php中return array();之前添加上述代码,表示函数的最后一个。

    现在下面获取访问会话变量

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-16
      • 2018-10-24
      • 2017-11-19
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多