سؤال

التعديل النهائي (تم الحل)

شكرا جزيلا لماريوس للإجابة على هذا السؤال.بمساعدته وبعض المعلومات من هذا السؤال, لقد تمكنت من تجميع حل عملي.إليك كتلة التعليمات البرمجية النهائية (العاملة):

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

السؤال الأصلي

كما رأينا في هذا السؤال (الإجابة الذاتية), ، أحاول ترميز شرط مخصص في إعداد الضريبة الخاص بي.

هذا يعمل بشكل مثالي على الواجهة الأمامية كان العمل على الواجهة الخلفية في وقت سابق.لم أغير الكود، لذا فأنا في حيرة من أمري بسبب عدم عمله الآن.

كيف أقوم بتحميل معرف العميل عندما أكون في صفحة إنشاء طلب جديد؟

الطريقة التي كنت أستخدمها بنجاح لم تعد تعمل مع سجل الأخطاء الخاص بي الذي يقول:

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();

أنت تحصل بشكل أساسي على معرف العميل من الجلسة، ثم تقوم بتحميل المنطقة بنفس معرف العميل.
أنا متأكد من أن هذا ليس ما تريد القيام به.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top