주문 페이지에서 고객 ID를 검색하는 방법
-
13-12-2019 - |
문제
최종 편집 (해결)
마리우스 덕분 에이 질문에 대답합니다. 이 질문 에서 몇 가지 정보와 함께 있습니다. 조각으로 작업 솔루션. 최종 (작업) 코드 블록은 다음과 같습니다.
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;
}
.
원래 질문
이 질문 (자아 -answered) , 내 세금 설정에 맞춤 조건을 코딩하려고합니다.이것은 프론트 엔드에서 완벽하게 작동하며 은 이전에 백엔드에서 작동합니다. 나는 코드를 변경하지 않았으므로 지금은 지금 작동하지 않는 이유에 대한 손실에 있습니다.
새 주문 만들기 페이지에있을 때 고객 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로 지역을로드합니다.
나는 이것이 당신이하고 싶은 것이 아닙니다.
제휴하지 않습니다 magento.stackexchange