根据magento签出页面中创建的自定义字段更改客户组
我在magento onepage签出页面中创建了一个自定义字段。当用户填写此字段时,其客户组应设置为组1,如果此字段留空,则其客户组应为组2 我的主要问题 1当用户通过结帐页面注册时,如何以编程方式设置客户组值 2如何在结帐过程中关联我的自定义字段值和客户组值根据magento签出页面中创建的自定义字段更改客户组,magento,checkout,Magento,Checkout,我在magento onepage签出页面中创建了一个自定义字段。当用户填写此字段时,其客户组应设置为组1,如果此字段留空,则其客户组应为组2 我的主要问题 1当用户通过结帐页面注册时,如何以编程方式设置客户组值 2如何在结帐过程中关联我的自定义字段值和客户组值 提前感谢。要解决上述问题,您需要使用magento的事件观察者模式,他们的事件称为customer_save_Prefore,这将帮助您获得所需的答案 现在,我们必须添加自定义模块。我正在给我的模块客户打电话,它是Npm小组的一部分。因
提前感谢。要解决上述问题,您需要使用magento的事件观察者模式,他们的事件称为customer_save_Prefore,这将帮助您获得所需的答案 现在,我们必须添加自定义模块。我正在给我的模块客户打电话,它是Npm小组的一部分。因此,该文件应命名为app/etc/modules/Npm_Customer.xml。将以下代码添加到此文件中:
<config>
<modules>
<Npm_Customer>
<active>true</active>
<codePool>local</codePool>
</Npm_Customer>
</modules>
</config>
接下来,我们需要为模块创建代码。我们的代码背后的想法是,我们将在事件之前在customer_save_上创建一个观察者。Magento有许多我们可以观察到的事件,但大多数都超出了本文的范围。有用的是,在创建客户和客户更改其帐户时都会调用customer_save_before事件。这意味着一个观察者将能够为两个事件做工作
我们为模块编写的所有代码都将位于app/code/local/Npm/Customer/目录中。第一个文件是etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Npm_Customer>
<version>1.0</version>
</Npm_Customer>
</modules>
<global>
<events>
<customer_save_before>
<observers>
<npm_customer_save_observer>
<type>singleton</type>
<class>Npm_Customer_Model_Customer_Observer</class>
<method>customerSaveBefore</method>
</npm_customer_save_observer>
</observers>
</customer_save_before>
</events>
</global>
</config>
下一步是创建我们刚刚告诉Magento我们将要使用的类,该类应该在Model/Customer/Observer.php文件中定义:
<?php
class Npm_Customer_Model_Customer_Observer extends Mage_Core_Model_Abstract
{
/*
* observer for the customer saved event
*/
public function customerSaveBefore($observer)
{
try {
$customer = $observer->getCustomer();
if (null != $customer->getPermissionCode()) {
$customer->setData('group_id', 4); // Set the new customer group
} else {
$customer->setData('group_id', 1); // Set to the default customer group
}
} catch ( Exception $e ) {
Mage::log("customer_save_before observer failed: " . $e->getMessage());
}
}
}
如果客户从注册表中提供了许可代码,则他们现在将自动分配到您的新组
谢谢如果客户群具有不同的税务等级,此解决方案是否会重新计算购物车价格?@Giuseppe,是的。我们只是在客户注册时才更改客户群,一切都会一样。这只是个问题,如果我在结账时尝试注册,我没有得到任何税务重新计算。我正在寻找这一点的解决方案,所以如果您在结账时注册,请让我知道您是否获得了适当的税务/不满。Thx@Giuseppe,您可以将此echo$this->helper'tax'->getPrice$\u product,$\u product->getPrice,true;并更新您的订单报价