您好,我想在填写信息后但在点击结帐按钮之前在结帐页面上保存新客户。是否有可能使用观察者或其他方法在数据库中创建和保存新客户?
答案 0 :(得分: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();
}
}
}
}
答案 1 :(得分:0)
您可以使用此观察员事件 checkout_controller_onepage_save_shipping_method 当客户继续使用送货方式时,此事件将会触发。
您可以从报价对象获取客户账单/送货地址。