Pregunta

EDICIÓN FINAL (resuelta)

Muchas gracias a Marius por responder esta pregunta.Con su ayuda y algo de información de esta pregunta, Pude encontrar una solución funcional.Aquí está el bloque de código final (en funcionamiento):

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

Pregunta original

Como se vio en esta pregunta (autorespondida), Estoy intentando codificar una condición personalizada en mi configuración de Impuestos.

Esto está funcionando perfectamente en la interfaz y era trabajando en el backend antes.No he cambiado el código, así que no sé por qué no funciona ahora.

¿Cómo cargo la identificación del cliente cuando estoy en la página Crear nuevo pedido?

El método que estaba usando con éxito ya no funciona y mi registro de errores dice:

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

Línea 658:

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

Esto está dentro del Tax/Model/Calculation.php archivo, por lo que hace referencia a este bloque de código:

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

El método que estoy modificando es 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;
}
¿Fue útil?

Solución

En lugar de

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

Intenta usar esto:

$cust = $this->getCustomer();

Pero ten cuidado. $cust tal vez null en algunos casos.

Como nota al margen, esto no tiene buena pinta:

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

Básicamente, obtiene la identificación del cliente de la sesión y luego carga la región con la misma identificación que el cliente.
Estoy seguro de que esto no es lo que quieres hacer.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top