Magento:我该如何回应用户名 [英] Magento : How do i echo username

查看:59
本文介绍了Magento:我该如何回应用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用现代主题

我在标题上有一个实时聊天按钮,我想解析模板中的信息

I have a livechat button on the header and i want to parse informations in my template

这是实时聊天按钮:

<!-- http://www.LiveZilla.net Chat Button Link Code --><a href="[removed]void(window.open('http://xxxxxx.fr/livezilla.php?code=BOUTIQUE&amp;en=<!!CUSTOMER NAME!!>&amp;ee=<!!!CUSTOMER EMAIL!!>.........

我需要替换并替换为用户名和电子邮件地址(如果已登录)

I need to replace and to the name and the email of the user (if logged)

该按钮位于我首页的标题中

The button is in the header of my homepage

我如何回显这两个信息?

How do i echo this two informations ?

我尝试过

<?php echo $this->htmlEscape($this->getCustomer()->getName()) ?>

但无效:

致命错误:调用成员函数 getFirstname()在非对象中 /home/xxx/public_html/app/design/frontend/default/modern/template/page/html/header.phtml 在第36行

Fatal error: Call to a member function getFirstname() on a non-object in /home/xxx/public_html/app/design/frontend/default/modern/template/page/html/header.phtml on line 36

推荐答案

那是正常的. 模板app/design/frontend/default/modern/template/page/html/header.phtml对应的块位于app/code/Core/Page/Block/Html/Header.php.

that's normal. The block corresponding to the template app/design/frontend/default/modern/template/page/html/header.phtml is located at app/code/Core/Page/Block/Html/Header.php.

如果阅读该块的代码,将会看到没有名为"getCustomer()"的函数. 而且,当您尝试在模板页面上调用$this->getCustomer()->getName();时,由于getCustomer()函数不存在,因此不会返回任何内容.

If you read the code of the block, you will see that there is no function called 'getCustomer()'. And when you try to call $this->getCustomer()->getName(); on your template page, as the function getCustomer() doesn't exist, it doesn't return anything.

结果是您随后尝试什么都不调用'getName()',并且出现错误消息:Fatal error: Call to a member function getFirstname() on a non-object.

The result is that you are then trying to call 'getName()' on nothing.. and there goes the error message : Fatal error: Call to a member function getFirstname() on a non-object.

您可以阅读:在非对象上调用成员函数getFirstname().

As you can read : Call to a member function getFirstname() on a non-object.

如果要在header.phtml中获取客户名称,则应该执行以下操作:

If you want to get the customer name in the header.phtml you should do :

$session = Mage::getSingleton('customer/session');
if($session->isLoggedIn()) {
   $customer = $session->getCustomer();
   echo $customer->getName();
   echo $customer->getFirstname();
}

胡格斯

这篇关于Magento:我该如何回应用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆