How to display telephone number and detail after customer login in magento using API.
<?php
/* customer Loggin Code */
require_once("../../app/Mage.php");
umask(0);
Mage::app('default');
ini_set('display_errors', 1);
ob_start();
session_start();
/* inputs */
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
/* inputs */
Mage::getSingleton("core/session", array("name" => "frontend"));
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
try
{
$customer->loadByEmail($email);
$session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
$session->login($email, $password);
$customerData = Mage::getModel('customer/customer')->load($session->getId())->getData();
$customer_id=$customerData['entity_id'];//for getting the customer ID.
$visitorData = Mage::getModel('customer/customer')->load($customer_id);
$billingaddress = Mage::getModel('customer/address')->load($visitorData->default_billing);
$addressdata = $billingaddress ->getData();//for getting the billingaddress
json_encode($customerData['email']);
if($customerData['email']): /* checking db emails */
$result['status'] = 'logged in';
$resphone['phone']=$addressdata['telephone'];
$get=array_merge($resphone,$customerData);
$result['getdata']=$get;
echo json_encode($result);
else:
$result = array('status' => 'notloggedin' , 'msg' => 'Invalid Email or Password!');
echo json_encode($result);
endif;
}
catch(Exception $e){
$result = array('status' => 'notloggedin' , 'msg' => 'Invalid Email or Password!');
echo json_encode($result);
}
?>
/* customer Loggin Code */
require_once("../../app/Mage.php");
umask(0);
Mage::app('default');
ini_set('display_errors', 1);
ob_start();
session_start();
/* inputs */
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
/* inputs */
Mage::getSingleton("core/session", array("name" => "frontend"));
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
try
{
$customer->loadByEmail($email);
$session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
$session->login($email, $password);
$customerData = Mage::getModel('customer/customer')->load($session->getId())->getData();
$customer_id=$customerData['entity_id'];//for getting the customer ID.
$visitorData = Mage::getModel('customer/customer')->load($customer_id);
$billingaddress = Mage::getModel('customer/address')->load($visitorData->default_billing);
$addressdata = $billingaddress ->getData();//for getting the billingaddress
json_encode($customerData['email']);
if($customerData['email']): /* checking db emails */
$result['status'] = 'logged in';
$resphone['phone']=$addressdata['telephone'];
$get=array_merge($resphone,$customerData);
$result['getdata']=$get;
echo json_encode($result);
else:
$result = array('status' => 'notloggedin' , 'msg' => 'Invalid Email or Password!');
echo json_encode($result);
endif;
}
catch(Exception $e){
$result = array('status' => 'notloggedin' , 'msg' => 'Invalid Email or Password!');
echo json_encode($result);
}
?>
No comments:
Post a Comment