最终编辑(已解决)

非常感谢马吕斯回答这个问题。在他的帮助和一些信息的帮助下 这个问题, ,我能够拼凑出一个可行的解决方案。这是最终的(工作的)代码块:

public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
    $cust = $this->getCustomer();
    $custId = $cust->getId();
    $vat = $cust->getData('taxvat');

    $custAddress = Mage::getModel('customer/address')->load($cust->default_shipping);
    $custState = $custAddress->getData('region');

    $customerLoggedIn = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getRegion();
    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
        $amount = $price * (1 - 1 / (1 + $taxRate));
    } else if (strtoupper($custState) === 'FLORIDA' || strtoupper($customerLoggedIn) === 'FLORIDA') {
        if ($vat) {
            $amount = $price;
        } else {
            $amount = $price * $taxRate;
        }
    } else {
        $amount = 0;
    }

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

    return $amount;
}

原始问题

正如所见 这个问题(自己回答), ,我正在尝试将自定义条件编码到我的税务设置中。

这在前端运行得很好 曾是 早些时候在后端工作。我没有更改代码,所以我很不知道为什么它现在不起作用。

当我在“创建新订单”页面上时,如何加载客户 ID?

我成功使用的方法不再适用于我的错误日志:

Undefined variable: customerId  in /app/code/local/Mage/Tax/Model/Calculation.php on line 658

658行:

$cust = Mage::getModel('customer/customer')->load($customerId);

这是在 Tax/Model/Calculation.php 文件,因此它引用此代码块:

public function getCustomer()
{
    if ($this->_customer === null) {
        $session = Mage::getSingleton('customer/session');
        if ($session->isLoggedIn()) {
            $this->_customer = $session->getCustomer();
        } elseif ($session->getCustomerId()) {
            $this->_customer = Mage::getModel('customer/customer')->load($session->getCustomerId());
        } else {
            $this->_customer = false;
        }
    }
    return $this->_customer;
}

我修改的方法是 calcTaxAmount:

public function calcTaxAmount($price, $taxRate, $priceIncludeTax = false, $round = true)
{
    $cust = Mage::getModel('customer/customer')->load($customerId);
    $vat = $cust->getData('taxvat');

    $customerLoggedIn = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getRegion();
    $taxRate = $taxRate / 100;

    if ($priceIncludeTax) {
        $amount = $price * (1 - 1 / (1 + $taxRate));
    } else if (strtoupper($customerLoggedIn) === 'FLORIDA') {
        if ($vat) {
            $amount = $price;
        } else {
            $amount = $price * $taxRate;
        }
    } else {
        $amount = 0;
    }

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

    return $amount;
}
有帮助吗?

解决方案

代替

$cust = Mage::getModel('customer/customer')->load($customerId);

尝试使用这个:

$cust = $this->getCustomer();

不过要小心。 $cust 或许 null 在某些情况下。

顺便说一句,这看起来不太好:

$custAdmin = Mage::getSingleton('customer/session')->getCustomer();
$custAdminId = $custAdmin->getId();
$region = Mage::getModel('directory/region')->load($custAdminId);
$stateCode = $region->getCode();
$stateName = $region->getName();

您基本上是从会话中获取客户 ID,然后加载与客户具有相同 ID 的区域。
我确信这不是您想要做的。

许可以下: CC-BY-SA归因
scroll top