Customer Details in Magento
Load Customer using Id in Magento
$customer = Mage::getModel('customer/customer')->load($id); //returns customer data as a varien object $customer = Mage::getModel('customer/customer')->load($id)->getData(); //returns customer data as an array
Load Customer using Email in Magento
$customer = Mage::getModel("customer/customer"); $customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); $customer->loadByEmail($email); //if you are getting null value then check what getWebsiteId() returns
Load logged in Customer from session in Magento
$customer = Mage::getSingleton('customer/session')->getCustomer(); //returns customer data as a varien object
Load Customer using Helper in Magento
$customer = Mage::helper('customer')->getCustomer(); //returns customer data as a varien object
Getting Customer Details in Magento
After loading customer as an object, you can assess variour methods.
//Generally used methods $customer->getName(); // returns full name` $customer->getFirstname(); // returns first name $customer->getMiddlename(); // returns middle name $customer->getLastname(); // returns last name $customer->getEmail(); // returns email $customer->getGroupId(); // returns customer group id $customer->getDefaultBilling(); $customer->getDefaultShipping(); //Other customer data $customer->getPrefix(); // returns customer prefix $customer->getSuffix(); // returns customer suffix $customer->getWebsiteId(); $customer->getEntityId(); $customer->getEntityTypeId(); $customer->getAttributeSetId(); $customer->getStoreId(); $customer->getCreatedAt(); $customer->getUpdatedAt(); $customer->getIsActive(); $customer->getDisableAutoGroupChange(); $customer->getTaxvat(); $customer->getPasswordHash(); $customer->getCreatedIn(); $customer->getGender(); $customer->getDob(); $customer->getTaxClassId();
If you have data in array format, use var_dump to check what your variable holds.
Check whether customer is logged-in
$logged = Mage::getSingleton("customer/session")->isLoggedIn(); //returns true or false //using session $logged = $this->helper("customer")->isLoggedIn(); //using helper
Get Customer Group Code in Magento
$customer = Mage::getModel('customer/customer')->load($id); $groupId = $customer->getGroupId(); $groupCode = Mage::getModel('customer/group')->load($groupId)->getCustomerGroupCode(); //returns group code (general, retailer, etc)
Get Customer default billing/shipping address in Magento
//getting default billing address $customerBillingAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling(); $defaultBillingAddress = Mage::getModel('customer/address')->load($customerBillingAddressId); $defaultBillingAddress = $defaultBillingAddress->getData(); //return as array //getting default shipping address $customerShippingAddressId = Mage::getModel('customer/customer')->load($id)->getDefaultShipping(); $defaultShippingAddress = Mage::getModel('customer/address')->load($customerShippingAddressId); //address as object $defaultShippingAddress = $defaultShippingAddress->getData(); //return as array //in case if you want to get address as object $address = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling(); $address = Mage::getModel('customer/address')->load($customerBillingAddressId); $firstName = $address->getFirstname() $lastName = $address->getLastname(); $company = $address->getCompany(); $zip = $address->getPostcode(); $city = $address->getCity(); $street = $address->getStreet(); $telephone = $address->getTelephone(); $fax = $address->getFax(); $country = $address->getCountry();