tags:

views:

4520

answers:

5

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. ?

A: 

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

Click Upvote
The code showing that is <?php echo $this->getWelcome() ?> in header.phtml. No idea where it gets the name from...
Eran Kampf
If you can edit your question and add to it the output of that function, I can write some PHP code for you to extract the username out of it. Magento has gazillions of files, so it can be pretty hard to tell where a particular function is stored
Click Upvote
Thanks but I can write the code that extracts the name from the welcome string. However I was hoping to be able to read other data other than the name - specifically, a unique user account ID.
Eran Kampf
+4  A: 

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();
nlaq
A: 

How do I extract email of the current user?

A: 

for Email use this code

$email=$this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getEmail());

echo $email;
AK
A: 

For username is same with some modification:

$user=$this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getName()); echo $user;

Vexcor Systems