I'm customizing the product view page and I need to show the user's name. How do I access the account information of the current user (if he's logged in) to get Name etc. ?
I don't know this off the top of my head, but look in the file which shows the user's name, etc in the header of the page after the user has logged in. It might help if you turned on template hints (see this tutorial.
When you find the line such as "Hello <? //code for showing username?>"
, just copy that line and show it where you need to
Found under "app/code/core/Mage/Page/Block/Html/Header.php":
public function getWelcome()
{
if (empty($this->_data['welcome'])) {
if (Mage::app()->isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) {
$this->_data['welcome'] = $this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getName());
} else {
$this->_data['welcome'] = Mage::getStoreConfig('design/header/welcome');
}
}
return $this->_data['welcome'];
}
So it looks like "Mage::getSingleton('customer/session')->getCustomer()" will get your current logged in customer ;)
To get the currently logged in admin:
Mage::getSingleton('admin/session')->getUser();
for Email use this code
$email=$this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getEmail());
echo $email;
For username is same with some modification:
$user=$this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getName()); echo $user;