php Magento 的当前用户?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/416553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:41:29  来源:igfitidea点击:

Current user in Magento?

phpmagento

提问by Eran Kampf

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

我正在自定义产品视图页面,我需要显示用户名。如何访问当前用户的帐户信息(如果他已登录)以获取姓名等?

回答by

Found under "app/code/core/Mage/Page/Block/Html/Header.php":

在“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 ;)

所以看起来Mage::getSingleton('customer/session')->getCustomer()会让你当前登录的客户;)

To get the currently logged in admin:

要获取当前登录的管理员:

Mage::getSingleton('admin/session')->getUser();

回答by Mukesh Chapagain

Have a look at the helper class: Mage_Customer_Helper_Data

看看辅助类:Mage_Customer_Helper_Data

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

要简单地获取客户名称,您可以编写以下代码:-

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

For more information about the customer's entity id, website id, email, etc. you can use getCustomerfunction. The following code shows what you can get from it:-

有关客户实体 ID、网站 ID、电子邮件等的更多信息,您可以使用getCustomer函数。以下代码显示了您可以从中获得的信息:-

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

From the helper class, you can also get information about customer login url, register url, logout url, etc.

从helper类还可以获取客户登录url、注册url、注销url等信息。

From the isLoggedInfunction in the helper class, you can also check whether a customer is logged in or not.

从helper 类中的isLoggedIn函数,您还可以检查客户是否已登录。

回答by Deepak Mankotia

You can get current login customer name from session in following way :

您可以通过以下方式从会话中获取当前登录客户名称:

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

This will return the customer details of current login customer.

这将返回当前登录客户的客户详细信息。

Now you can get customer name by using getName()

现在您可以通过使用获取客户名称 getName()

echo $customer->getName();

回答by AK.

for Email use this code

对于电子邮件使用此代码

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

echo $email;

回答by Shorabh

$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();

Get customer Default Billing address

获取客户默认帐单地址

回答by Vexcor Systems

For username is same with some modification:

对于用户名是相同的一些修改:

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

回答by Alexandar

The following way you can access all the information from logged user.

您可以通过以下方式访问登录用户的所有信息。

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


echo "<pre>" print_r($customer_data);

回答by Fujy

This way:

这边走:

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

回答by Manikandan Arunachalam

Simply,

简单地,

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

This returns the customer object, then you can get all the details from this customer object.

这将返回客户对象,然后您可以从该客户对象中获取所有详细信息。

回答by Click Upvote

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

当您找到诸如 之类的行时"Hello <? //code for showing username?>",只需复制该行并将其显示在您需要的位置