.

.

New Customer Registration in Magento Programmatically

create a new customer through a signup form, in some cases, that might take too long.

For starters, let’s add a customer with some basic information.

<?php 
require_once '../app/Mage.php';
Mage::app();
header("Content-Type: application/json");
?> <?php
if($_POST)
{
$firstname=str_replace("'","`",$_POST['firstname']);
$lastname=str_replace("'","`",$_POST['lastname']);
$emailid=str_replace("'","`",$_POST['emailid']);
$password=$_POST['password'];
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer   ->setWebsiteId($websiteId)
            ->setStore($store)
            ->setFirstname($firstname)
            ->setLastname($lastname)          
            ->setEmail($emailid)
            ->setPassword($password);
try{
    $customer->save();
    $data['responseCode']='1';
    $data['msg']='Registered successful';  
}
catch (Exception $e) {
    Zend_Debug::dump($e->getMessage());
    $data['responseCode']='0';
    $data['msg']='Already Exist';
}
}
else
{
$data['responseCode']='0';
$data['msg']="Enter All Fields";
}
//print_r($data);
$data2 = json_encode($data);
echo $data2;

?>



EmoticonEmoticon