Magento customer registration programmatically

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 = ""; // 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)
    $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 = "";
if($sessionCustomer->isLoggedIn()) {
    header('Location: '. $red_url);
    //echo $setEmail." ".$setPassword;
    //header('Location: '. $red_url);
// function for login user programmatically
function loginUser($user_email,$user_password){
    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;
        $session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer_detail);
    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

Leave a Comment

Your email address will not be published. Required fields are marked *

2  +  4  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US