I would like to save customer in database, when someone filled billing information and hit the 'continue' button. Does anyone know how to do it?
I am using magento 1.9.2 and i tried with event "controller_action_postdispatch_checkout_onepage_saveBilling" but its not working over there, nothing happen with event or observer.
After saving customer in database i would like to logged in with that customer id, and need to refresh the page, or any other way is welcomed.
I would like to know how to do this ? if any idea please share here.
code as below :
create Utsav_Customersave.xml in app/etc/modules/
<?xml version="1.0"?>
<config>
<modules>
<Utsav_Customersave>
<active>true</active>
<codePool>local</codePool>
</Utsav_Customersave>
</modules>
in app/code/local/Utsav/Customersave/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Utsav_Customersave>
<version>1.0.0</version>
</Utsav_Customersave>
</modules>
<global>
<events>
<sales_quote_address_save_after>
<observers>
<auto_register_shipping>
<type>singleton</type>
<class>Utsav_Customersave_Model_Observer</class>
<method>autoRegisterBilling</method>
</auto_register_shipping>
</observers>
</sales_quote_address_save_after>
</events>
</global>
</config>
in app/code/local/Utsav/Customersave/Model/Observer.php
<?php
class Utsav_Customersave_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();
}
}
}
}