在magento中的Mage_Tax_Model_Calculation::getRate中获取客户

发布于 2024-10-01 06:10:16 字数 216 浏览 4 评论 0原文

我已经覆盖了 Mage_Tax_model_Calculation::getRate,因此我不想对某些客户征税。我没有为他们设立特殊的客户类别。

我的客户模型中有一个自定义字段,我想在加载客户模型后检查该字段,如果该字段有值,我不会向他征税,否则我会调用 parent::getRate($request )

是否可以在函数中得到它。

I have overwritten the Mage_Tax_model_Calculation::getRate, so that I want to not tax certain customers. I do not have a special customer class for them.

I have a custom field in my customer model, which I want to check after I am able to load my customer model and if this field has a value I do not tax him, otherwise I call parent::getRate($request)

Is it possible to get that in the function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凑诗 2024-10-08 06:10:16

尝试这样的事情:

function getRate($request) {
    // find a customer ID
    $admin_session = Mage::getSingleton('adminhtml/session_quote');
    if($admin_session) {
        if($admin_session->getCustomerId()) {
            $customer_id = $admin_session->getCustomerId();
        }
    } else {
        $customer_id = Mage::getSingleton("customer/session")->getCustomerId();
    }

    // find customer attr
    if($customer_id) {
        $customer = Mage::getModel("customer/customer")->load($customer_id);
        if($customer->getSomeColumnValue()) {
             return 0;
        }
    }

    // fallthrough
    return parent::getRate($request);
}

希望有帮助!

谢谢,


编辑:好点;)

查看 adminhtml 代码,它似乎远不如普通客户代码有用。我希望能够致电 Mage::register 但没有发生。我找到了一个可能的解决方案,尽管在 Magento 中加载会话似乎有副作用。见上文。

重新编辑:将您的修复纳入后代。

Try something like this:

function getRate($request) {
    // find a customer ID
    $admin_session = Mage::getSingleton('adminhtml/session_quote');
    if($admin_session) {
        if($admin_session->getCustomerId()) {
            $customer_id = $admin_session->getCustomerId();
        }
    } else {
        $customer_id = Mage::getSingleton("customer/session")->getCustomerId();
    }

    // find customer attr
    if($customer_id) {
        $customer = Mage::getModel("customer/customer")->load($customer_id);
        if($customer->getSomeColumnValue()) {
             return 0;
        }
    }

    // fallthrough
    return parent::getRate($request);
}

Hope that helps!

Thanks,
Joe


EDIT: good point ;)

Looking through the adminhtml code, it seems to be far less useful than the normal customer code. I was hoping for a call to Mage::register but that's not happening. I found a possible solution, though loading sessions in Magento seems to have side effects. See above.

RE-EDIT: to incorporate your fixes for posterity.

執念 2024-10-08 06:10:16

尝试加载当前登录的客户:

$session = Mage::getSingleton('customer/session');
$customer = Mage::getModel('customer/customer')->load($session->getCustomerId());
$customValue = $customer->getCustomFieldName();

干杯,
京东

Try this to load the current logged-in customer:

$session = Mage::getSingleton('customer/session');
$customer = Mage::getModel('customer/customer')->load($session->getCustomerId());
$customValue = $customer->getCustomFieldName();

Cheers,
JD

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文