Registration api in magento to check the email address and
phone no. if email and phone no are already exit then show message email
already exit and phone no already exit
<?php
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$fname = $_REQUEST['fname'];
$lname =$_REQUEST['lname'];
$email = $_REQUEST['email'];
$password =$_REQUEST['password'];
$phone=$_REQUEST['phone'];
$collection = Mage::getModel('customer/address')
->getCollection()
->addAttributeToSelect('*');
$c=0;
foreach ($collection as $customer) {
$telephone[$i]=$customer->getTelephone();
if($telephone[$i]==$phone){
$c++; break;
}
}
$customer = Mage::getModel('customer/customer');
if ($websiteId) {
$customer->setWebsiteId($websiteId);
}
$customer->loadByEmail($email);
if ($customer->getId()) {
$result = array('status' => 'notloggedin' , 'msg' => 'email already exists');
} else if($c>0){
$result = array('status' => 'notloggedin' , 'msg' => 'Phone No already exists');
}else {
$customer = Mage::getModel("customer/customer");
$customer ->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($fname)
->setLastname($lname)
->setEmail($email)
->setPassword($password);
try{
if($customer->save()){
$customer->save();
$customer->setConfirmation(null);
$customer->save();
$customer->sendNewAccountEmail();
setcookie('loginuser', $customer->getId(), time() + (10*24*60*60*1000), "/");
$result = array('status' => 'success','msg' => 'registration completed', 'customer_id' => $customer->getId());
$address = Mage::getModel("customer/address");
$address->setCustomerId($customer->getId())
->setFirstname($customer->getFirstname())
->setMiddleName($customer->getMiddlename())
->setLastname($customer->getLastname())
->setTelephone($phone);
$address->save();
}
}
catch (Exception $e) {
Zend_Debug::dump($e->getMessage());
}
}
echo json_encode($result);
require_once("../../app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$fname = $_REQUEST['fname'];
$lname =$_REQUEST['lname'];
$email = $_REQUEST['email'];
$password =$_REQUEST['password'];
$phone=$_REQUEST['phone'];
$collection = Mage::getModel('customer/address')
->getCollection()
->addAttributeToSelect('*');
$c=0;
foreach ($collection as $customer) {
$telephone[$i]=$customer->getTelephone();
if($telephone[$i]==$phone){
$c++; break;
}
}
$customer = Mage::getModel('customer/customer');
if ($websiteId) {
$customer->setWebsiteId($websiteId);
}
$customer->loadByEmail($email);
if ($customer->getId()) {
$result = array('status' => 'notloggedin' , 'msg' => 'email already exists');
} else if($c>0){
$result = array('status' => 'notloggedin' , 'msg' => 'Phone No already exists');
}else {
$customer = Mage::getModel("customer/customer");
$customer ->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($fname)
->setLastname($lname)
->setEmail($email)
->setPassword($password);
try{
if($customer->save()){
$customer->save();
$customer->setConfirmation(null);
$customer->save();
$customer->sendNewAccountEmail();
setcookie('loginuser', $customer->getId(), time() + (10*24*60*60*1000), "/");
$result = array('status' => 'success','msg' => 'registration completed', 'customer_id' => $customer->getId());
$address = Mage::getModel("customer/address");
$address->setCustomerId($customer->getId())
->setFirstname($customer->getFirstname())
->setMiddleName($customer->getMiddlename())
->setLastname($customer->getLastname())
->setTelephone($phone);
$address->save();
}
}
catch (Exception $e) {
Zend_Debug::dump($e->getMessage());
}
}
echo json_encode($result);
No comments:
Post a Comment