FINAL EDIT (resolved)
A big thanks to Marius for answering this question. With his help and some information from this question, I was able to piece together a working solution. Here is the final (working) code block:
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;
}
Original Question
As seen in this question (self-answered), I am trying to code a custom condition into my Tax setup.
This is working perfectly on the frontend and it was working on the backend earlier. I haven't changed the code, so I'm rather at a loss to why it isn't working now.
How do I load the Customer ID when I am on the Create New Order page?
The method I was using successfully is no longer working with my error log saying:
Undefined variable: customerId in /app/code/local/Mage/Tax/Model/Calculation.php on line 658
Line 658:
$cust = Mage::getModel('customer/customer')->load($customerId);
This is within the Tax/Model/Calculation.php file, so it references this code block:
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;
}
The method I am modifying is 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;
}
658? – Marius Jun 24 '15 at 13:47calcTaxAmountmethod, within a local copy of theMage/Tax/Model/Calculation.phpfile, so there is a lot of code in the file, but it's all default other than this method. – travisw Jun 24 '15 at 13:53