We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

Create app/code/local/Namespace/Module/etc/config.xml  file and add below code

<events>
  <checkout_onepage_controller_success_action> <!-- identifier of the event we want to catch -->
    <observers>
      <checkout_onepage_controller_success_action_handler> <!-- identifier of the event handler -->
        <type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
        <class>createcustomer/observer</class> <!-- observers class alias -->
        <method>Aftersuccess</method>  <!-- observer's method to be called -->
        <args></args> <!-- additional arguments passed to observer -->
      </checkout_onepage_controller_success_action_handler>
    </observers>
  </checkout_onepage_controller_success_action>
</events>

Create app/code/local/Namespace/Module/Model/Observer.php file and add the below code.

<?php
class Namespace_Module_Model_Observer
{

	public function Aftersuccess(Varien_Event_Observer $observer)
	{
		$orderIds = $observer->getData('order_ids');
     	        foreach($orderIds as $_orderId){
			$order = Mage::getModel('sales/order')->load($_orderId);
			$storeId = Mage::app()->getStore()->getId();
			$store = Mage::getModel('core/store')->load($order->getData('store_id'));
			$websiteId = $store->getWebsiteId();
			$billingaddress = $order->getBillingAddress();
			$customer = Mage::getModel('customer/customer')->setWebsiteId($websiteId);
			$customer->loadByEmail($order->getCustomerEmail());

			if(!$customer->getId()) {
				$customer = Mage::getModel("customer/customer");
				$customer   ->setWebsiteId($websiteId)
				            ->setStore($store)
				            ->setFirstname($billingaddress->getFirstname())
				            ->setLastname($billingaddress->getLastname())
				            ->setEmail($billingaddress->getEmail());
				try{
				    $customer->save();
				}
				catch (Exception $e) {
				    Zend_Debug::dump($e->getMessage());
				}

				$address = Mage::getModel("customer/address");
				$address->setCustomerId($customer->getId())
				        ->setFirstname($customer->getFirstname())
				        ->setMiddleName($customer->getMiddlename())
				        ->setLastname($customer->getLastname())
				        ->setCountryId($billingaddress->getCountryId())
						->setRegionId($billingaddress->getRegionId()) //state/province, only needed if the country is USA
				        ->setPostcode($billingaddress->getPostcode())
				        ->setCity($billingaddress->getCity())
				        ->setTelephone($billingaddress->getTelephone())
				        ->setFax($billingaddress->getFax())
				        ->setCompany($billingaddress->getCompany())
				        ->setStreet($billingaddress->getStreet())
				        ->setIsDefaultBilling('1')
				        ->setIsDefaultShipping('1')
				        ->setSaveInAddressBook('1');
				 
				try{
				    $address->save();
				}
				catch (Exception $e) {
				    Zend_Debug::dump($e->getMessage());
				}
			}
		}
	}	
}

 

field_5bfb909c5ccae

    Recent Articles
    Get a Free Quote

      Let’s initiate a discussion!!