Magento get the logged in customer details like customer id, name, email, etc. Check if customer is already logged in or not, if they are logged in then get all the data using customer session object and use it as per the requirement.

Input:

[php toolbar=”true” classname=”one_line”] if (Mage::getSingleton(‘customer/session’)->isLoggedIn()) {
$customer = Mage::getSingleton(‘customer/session’)->getCustomer();
$customerData = Mage::getModel(‘customer/customer’) ->load($customer->getId())->getData();
Mage::log($customerData);
}
[/php]

Output:

[php toolbar=”true” classname=”one_line”] Array
(
[entity_id] => 1
[entity_type_id] => 1
[attribute_set_id] => 0
[website_id] => 1
[email] => john.doe@example.com
[group_id] => 1
[increment_id] => 000000001
[store_id] => 1
[created_at] => 2007-08-30 23:23:13
[updated_at] => 2008-08-08 12:28:24
[is_active] => 1
[firstname] => John
[lastname] => Doe
[password_hash] => 204948a4020ed1d0e4238db2277d5:eg
[prefix] =>
[middlename] =>
[suffix] =>
[taxvat] =>
[default_billing] => 274
[default_shipping] => 274
)
[/php]

Getting customer details from the $customerData object:

[php toolbar=”true” classname=”one_line”] $customerID = $customerData->getId(); //entity_id can be used as id
$name = $customerData->getFirstname() . ‘ ‘ . $customerData->getLastname();
$isActive = $customerData->getIsActive();
$email = $customerData->getEmail();
$incrId = $customerData->getIncrementId();
[/php]

Also use this Code:

[php toolbar=”true” classname=”one_line”] /* Check if the customer is logged in or not */
if (Mage::getSingleton(‘customer/session’)->isLoggedIn()) {

/* Get the customer data */
$customer = Mage::getSingleton(‘customer/session’)->getCustomer();
/* Get the customer’s full name */
$fullname = $customer->getName();
/* Get the customer’s first name */
$firstname = $customer->getFirstname();
/* Get the customer’s last name */
$lastname = $customer->getLastname();
/* Get the customer’s email address */
$email = $customer->getEmail();

}
[/php]

Leave A Comment