Wednesday 21 December 2016

How to get customer details in frontend of magento

Many time we need customer data when we go through custom module.

Customer is saved in session so we can get customer data using following script.

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$data = Mage::getSingleton('customer/session')->getCustomer();
}

Or you can direct get customer id or customer name using of following script.

For First name :
Mage::getSingleton('customer/session')->getCustomer()->getData('firstname');

For customer id :
Mage::getSingleton('customer/session')->getCustomer()->getId();

If you have any query then feel free to contact me at Jainish Senjaliya

How to get customer details in backend admin panel order of magento

If we go through custom module than many time we need customer data on order create page.

Customer is saved in session so we can get customer data using following script.

Mage::getSingleton('adminhtml/session_quote')->getCustomer();

Or you can direct get customer id or customer name using of following script.

For First name :
Mage::getSingleton('adminhtml/session_quote')->getCustomer()->getData('firstname');

For customer id :
Mage::getSingleton('adminhtml/session_quote')->getCustomer()->getId();

If you have any query then feel free to contact me at Jainish Senjaliya