您好,我想在填写信息后但在单击结帐按钮之前在结帐页面上保存新客户。是否有可能通过使用观察者或其他方法在数据库中创建和保存新客户?
问问题
1549 次
2 回答
0
您可以使用此观察者事件checkout_controller_onepage_save_shipping_method当客户继续使用运输方法时,此事件将触发。
您可以从报价对象获取客户帐单/送货地址。
于 2013-07-31T04:22:12.613 回答
0
编写一个观察者来触发保存运输事件并保存客户。
例如:
在 app/etc/modules/ 中创建 Yournamespace_Yourmodulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Yournamespace_Yourmodulename>
<active>true</active>
<codePool>local</codePool>
</Yournamespace_Yourmodulename>
</modules>
在 app/code/local/Yournamespace/Yourmodulename/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Yournamespace_Yourmodulename>
<version>1.0.0</version>
</Yournamespace_Yourmodulename>
</modules>
<global>
<events>
<checkout_controller_onepage_save_shipping_method>
<observers>
<auto_register_shipping>
<type>singleton</type>
<class>Yournamespace_Yourmodulename_Model_Observer</class>
<method>autoRegisterBilling</method>
</auto_register_shipping>
</observers>
</checkout_controller_onepage_save_shipping_method>
</events>
</global>
</config>
在 app/code/local/Yournamespace/Yourmodulename/Model/Observer.php
<?php
class Yournamespace_Yourmodulename_Model_Observer {
public function autoRegisterBilling($evt){
if(!Mage::helper('customer')->isLoggedIn()){
$data = $evt->getEvent()->getControllerAction()->getRequest()->getPost('billing', array());
$customer = Mage::getModel("customer/customer");
$email = $data['email'];
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$pwd = $data['customer_password'];
$customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($email);
if (!$customer->getId()) {
//Code begins here for new customer registration
$customer->website_id = $websiteId;
$customer->setStore($store);
$customer->firstname = $data['firstname'];
$customer->lastname = $data['lastname'];
$customer->setEmail($email);
$customer->setPassword($pwd);
$customer->sendNewAccountEmail('confirmed');
$customer->save();
}
}
}
}
于 2013-07-30T06:39:09.180 回答