Magento Get Customer Details


Magento Get Customer Details : If you are working with magento you often need to work with customer related module and you need to get/set customer data. You can get customer information using the model customer/customer. You can get or set the customer data using this model. Here we are going to explain how to get customer data in magento using customer id or customer session.


Magento Get Customer Details

Here is the detail which you can access using the customer model. Lets go in detail step by step –

Magento Get Customer Id From Session

Here is syntax for getting customer id from customer session-

Magento Get Customer Id From Session


    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $customerId = $customer->getId();
  

Which will give you the customer id.

Magento Get Customer data from customer Id

Here is syntax for getting customer data from customer id –

Magento load customer data from customer Id

   $customerId = 10;
   $customer = Mage::getModel('customer/customer')->load($customerId);
   echo $customer->getFirstname();

Which will load the customer data for the customer id 10.

Now Let’s go and get data loaded from the magento.

Magento Get Customer Name

You can get customer first and last name as below –

Magento load customer data from customer Id

   $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
   $customer = Mage::getModel('customer/customer')->load($customerId);
   echo $customer->getFirstname()."<br>";
   echo $customer->getLastname()."<br>";

Which will give you customer’s name.

Magento Get Customer Group Id

You can get customer group id as below –

Magento get customer group id

   $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
   $customer = Mage::getModel('customer/customer')->load($customerId);
   echo $customer->getGroupId();

Which will give you customer’s group id.

Magento Get Customer Email Id

You can get customer email id as below –

Magento get customer email id

   $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
   $customer = Mage::getModel('customer/customer')->load($customerId);
   echo $customer->getEmail();

Which will give you customer’s email.

Magento Get Customer Address Detail

You can get customer Address Detail such as below –

  • First Name
  • Last Name
  • Company
  • Post Code
  • City
  • Street
  • Telephone
  • Fax
  • Country

Magento get customer Address Detail


   $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
   $customer = Mage::getModel('customer/customer')->load($customerId);
  // get billing address id 
   $customerAddressId = $customer->getDefaultBilling();

   // now get addredd detail 

   $address  = Mage::getModel('customer/address')->load($customerAddressId);
   echo $address->getFirstname().'<br>';
   echo $address->getLastname().'<br>';
   echo $address->getCompany().'<br>';
   echo $address->getPostcode().'<br>';
   echo $address->getCity().'<br>';
   echo $address->getStreert()[0].'<br>';
   echo $address->getTelephone().'<br>';
   echo $address->getFax().'<br>';
   echo $address->getCountry().'<br>';
    

Which will give you customer’s email.


Advertisements

Add Comment

đź“– Read More