1

I want save customer register information once billing information saved(click continue button) .for that i created one module with following files.Please direction me where i'm wrong.thanks in advance.
etc/modules

<?xml version="1.0"?>
<config>
<modules>
    <Exinent_Billingtax>
        <active>true</active>
        <codePool>local</codePool>
    </Exinent_Billingtax>
</modules>
</config>

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Exinent_Billingtax>
        <version>1.0.0</version>
    </Exinent_Billingtax>
</modules>
<global>
    <events>
              <controller_action_postdispatch_checkout_onepage_saveBilling>
            <observers>
                <auto_register_billing>
                    <type>singleton</type>
                    <class>Exinent_Billingtax_Model_Observer</class>
                    <method>autoRegisterBilling</method>
                </auto_register_billing>
            </observers>
                </controller_action_postdispatch_checkout_onepage_saveBilling>
    </events>
</global>
</config>

Observer.php

<?php
class Exinent_Billingtax_Model_Observer {
    public function autoRegisterBilling($evt){
        if(!Mage::helper('customer')->isLoggedIn()){
            $data = $evt->getEvent()->getControllerAction()->getRequest()->getPost('billing', array());
            echo "<pre>";
            print_r($data);
            $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();
                   }
            Mage::getSingleton('customer/session')->loginById($customer->getId()); // to login that customer.
           }
    }

}

2 Answers 2

1

Customer has been not loggin properly... you need forcefully login and need to page refresh

<?php
class Exinent_Billingtax_Model_Observer {
    public function autoRegisterBilling($evt){
        if(!Mage::helper('customer')->isLoggedIn()){
            $data = $evt->getEvent()->getControllerAction()->getRequest()->getPost('billing', array());


            //echo "<pre>";
            //print_r($data);
            //echo "<pre>";
            Mage::log($data['lastname'],null,'amit.log');
            //return ;
            $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();
                   }
           // Mage::getSingleton('customer/session')->loginById($customer->getId()); // to login that customer.
            if($customer->getId()>0){
            $userSession = Mage::getSingleton('customer/session');
            $userSession->setCustomer($customer);
            Mage::dispatchEvent('customer_login', array('customer'=>$customer));
            Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/onepage'))->sendResponse();
exit;
            }

           }
    }

}
5
  • you really saves my time
    – sivakumar
    Jun 3, 2014 at 7:12
  • sorry to say above code is not working for me now.If i click continue nothing happening.Please once look at this.
    – sivakumar
    Jun 3, 2014 at 9:35
  • customer information saving in the db.but next tab not opening
    – sivakumar
    Jun 3, 2014 at 9:40
  • You need to reload page checkout/onepage/ for proper customer session set
    – Amit Bera
    Jun 3, 2014 at 9:45
  • yes.Is there way to refresh in observer file using some code?
    – sivakumar
    Jun 3, 2014 at 9:55
0

Have you defined your helper and Model class in config.xml file like this-

<global>
  <helpers>
      <module_name>
        <class>NameSpace_ModuleName_Helper</class>
      </module_name>
    </helpers>
    <models>
      <module_name>
        <class>NameSpace_ModuleName_Model</class>
        <resourceModel>module_name_mysql4</resourceModel>
      </module_name>
    </models>
</global>

Your Answer

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

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