質問

最終編集 (解決済み)

この質問に答えてくれたマリウスに感謝します。彼の助けといくつかの情報により、 この質問, 、実用的な解決策をまとめることができました。最終的な (動作する) コード ブロックは次のとおりです。

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帰属
所属していません magento.stackexchange
scroll top