Magento customer registration programmatically
This post is we will show you how to Magento customer registration programmatically.
first we create user ,if user is not exist then insert data into database then we will go for login to user programmatically.
// code for Magento customer registration $website_Id = Mage::app()->getWebsite()->getId(); $store_detail = Mage::app()->getStore(); $setFirstname = "Firstname"; // add First name $setLastname = "setLastname"; // add Last name $setEmail = "Ttest123@gm.co"; // add Email id $setPassword = "password@789"; // add password /*$setPostcode = "989898"; // add Post code $setCity = "Sydney "; // add city of user $setRegion = "New South Wales"; $setTelephone = "99999999999"; $setFax = "123456"; $setCompany = "Australia"; $setStreet = "in Australia some place";*/ $customer = Mage::getModel("customer/customer"); $customer ->setWebsiteId($website_Id) ->setStore($store_detail) ->setFirstname($setFirstname) ->setLastname($setLastname) ->setEmail($setEmail) ->setPassword($setPassword); try{ $results = $customer->save(); $getEntityId = $results->getEntityId(); // get user id } catch (Exception $exception) { // Magento customer registration // bug or user is exist echo $exception->getMessage(); // print Exception Message } Mage::getSingleton('core/session', array('name' => 'frontend')); $sessionCustomer = Mage::getSingleton("customer/session"); $red_url = "http://www.onlinecode.org/"; if($sessionCustomer->isLoggedIn()) { header('Location: '. $red_url); break; } else{ //echo $setEmail." ".$setPassword; loginUser($setEmail,$setPassword); //header('Location: '. $red_url); //break; } // function for login user programmatically function loginUser($user_email,$user_password){ umask(0); ob_start(); session_start(); Mage::app('default'); Mage::getSingleton("core/session", array("name" => "frontend")); $website_Id = Mage::app()->getWebsite()->getId(); $store_detail = Mage::app()->getStore(); $customer_detail = Mage::getModel("customer/customer"); $customer_detail->website_id = $website_Id; $customer_detail->setStore($store_detail); try { $customer_detail->loadByEmail($user_email); $session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer_detail); $session->login($user_email,$user_password); } catch(Exception $exception) { // customer registration echo $exception->getMessage(); // print Exception Message } }
You also like codeigniter select query and codeigniter join tables and Codeigniter Delete Query
Hope this code and post will helped you for implement Magento customer registration programmatically. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org