Current Magento user?

I am setting up a product view page and I need to show the username. How to access the account information of the current user (if he is logged in) to get a name, etc.?

+55
php magento
Jan 06 '09 at 13:43
source share
10 answers

Found in the section "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 registered client;)

To log in as an administrator:

 Mage::getSingleton('admin/session')->getUser(); 
+90
Jan 16 '09 at 22:51
source share

Take a look at the helper class: Mage_Customer_Helper_Data strong>

To just get the customer name, you can write the following code: -

 $customerName = Mage::helper('customer')->getCustomerName(); 

For more information about client object identifier, site identifier, email, etc. you can use the getCustomer function. The following code shows what you can get from it: -

 echo "<pre>"; print_r(Mage::helper('customer')->getCustomer()->getData()); echo "</pre>"; 

From the helper class, you can also get information about the login URL, registration URL, exit URL, etc.

In the isLoggedIn function in the helper class, you can also check if the client is registered or not.

+21
Feb 27 '11 at 18:08
source share

for Email use this code

 $email=$this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getEmail()); echo $email; 
+9
Dec 12 '09 at 16:45
source share

You can get the current login username from the session as follows:

 $customer = Mage::getSingleton('customer/session')->getCustomer(); 

This will return the client information of the current login client.

Now you can get the client name using getName()

 echo $customer->getName(); 
+8
Dec 16 '14 at 9:20
source share

For the username, the same with some modification:

 $user=$this->__('Welcome, %s!', Mage::getSingleton('customer/session')->getCustomer()->getName()); echo $user; 
+4
Jun 21 '10 at 17:04
source share

Below you can access all the information from a registered user.

 $customer_data=Mage::getSingleton('customer/session')->getCustomer(); echo "<pre>" print_r($customer_data); 
+4
Jul 22 '13 at 7:30
source share
 $ customer = Mage :: getSingleton ('customer / session') -> getCustomer ();
     $ customerAddressId = Mage :: getSingleton ('customer / session') -> getCustomer () -> getDefaultBilling ();
     $ address = Mage :: getModel ('customer / address') -> load ($ customerAddressId);
     $ fullname = $ customer-> getName ();
     $ firstname = $ customer-> getFirstname ();
     $ lastname = $ customer-> getLastname ();
     $ email = $ customer-> getEmail ();
     $ taxvat = $ customer-> getTaxvat ();
     $ tele = $ customer-> getTelephone ();
     $ telephone = $ address-> getTelephone ();
     $ street = $ address-> getStreet ();
     $ City = $ address-> getCity ();
     $ region = $ address-> getRegion ();
     $ postcode = $ address-> getPostcode ();
+4
Sep 23 '14 at 11:46
source share

In this way:

 $email = Mage::getSingleton('customer/session')->getCustomer()->getEmail(); echo $email; 
+2
Nov 12 2018-10-12T00:
source share

Simply,

 $current_customer = $this->_getSession()->getCustomer(); 

Returns a client object, then you can get all the details from this client object.

+2
Dec 16 '14 at 7:47
source share

I donโ€™t know this from the head, but look at the file that shows the username, etc. in the page title after user login. This may help if you have included template hints (see this tutorial .

When you find a line like "Hello <? //code for showing username?>" , Just copy this line and show it where you need it

-5
Jan 6 '09 at 13:50
source share



All Articles