0

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(); } } } }
5
  • try the even sales_quote_address_save_after Commented Feb 28, 2017 at 6:13
  • hi thanks for your reply but i tried with this below link stackoverflow.com/questions/17939733/… but nothing happen. as you suggested for "sales_quote_address_save_after" instead of "controller_action_postdispatch_checkout_onepage_saveBilling" should i directly use your given event ? Commented Feb 28, 2017 at 7:21
  • yes , you can use directly. Commented Feb 28, 2017 at 7:22
  • put your code that is used Commented Feb 28, 2017 at 7:37
  • code aded in main post please check Commented Feb 28, 2017 at 8:02

1 Answer 1

0

Please use the following code in config.xml and check your observer is cxecuting or not.

<?xml version="1.0"?>
<config>
<modules>
    <Customersave>
        <version>1.0.0</version>
    </Customersave>
</modules>
<global>
    <events>
        <controller_action_predispatch_checkout_onepage_saveBilling>
            <observers>
                <customersave>
                    <type>singleton</type>
                    <class>Utsav_Customersave_Model_Observer</class>
                    <method>autoRegisterBilling</method>
                </customersave>
            </observers>
        </controller_action_predispatch_checkout_onepage_saveBilling>
     </events>
 </global>  
</config>
9
  • I think that event was not firing somehow. Change the previous event as shown my edited answer. Commented Feb 28, 2017 at 9:42
  • i dont know but :( still not working.. observer is not cxecuting. Commented Feb 28, 2017 at 10:07
  • check your module is enabled or not Commented Feb 28, 2017 at 10:08
  • module is enabled but in 'core_resource" table there is no entry for this module, will it be there ? Commented Feb 28, 2017 at 10:24
  • No. it will not. you can try the code in default magento Commented Feb 28, 2017 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.