Magento – Getting the currently logged in customer or admin user

I know this has been explained elsewhere, but I wanted a central location I could reference as needed.
So, let’s get started.
If you are on a page in Magento, and want to get information about the currently logged in customer, or on the admin side, the admin user:

// Customer
$customer = Mage::getSingleton('customer/session')->getCustomer();
$custName = $customer->getName(); // Gets the customer's name

// Admin User
$adminUser = Mage::getSingleton('admin/session')->getUser();
$adminName = $adminUser->getName(); // Gets the admin's name.

There are other properties available on the customer and admin user, and these can be selected as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.