Magento网站的不同部分的客户会话是不同的 [英] Customer session is different in different parts of a Magento website
问题描述
我在Magento的Helper内部有一个函数,该函数返回customer属性是否等于一个.
I have a function inside of a Helper in Magento that returns whether or not a customer attribute equals one.
这是我的助手课程
class Nie_Nie_Helper_Data extends Mage_Core_Helper_Abstract {
public function isNieAdmin() {
if(Mage::getSingleton('customer/session')->getCustomer()->getNieAdmin() == 1) {
return true;
} else {
return false;
}
}
}
现在,当我从扩展Mage_Core_Block_Template的类中调用此函数时,一切似乎都可以正常工作.但是,当我尝试在我的一个控制器中使用它时,它不起作用.实际上,当我执行Mage::getSingleton('customer/session')->getCustomer()->debug()
时,唯一返回的变量是website_id.
Now when I call this function from a class that extends Mage_Core_Block_Template, everything seems to work fine. However when I try to use this inside one of my controllers, it does not work. In fact when I do Mage::getSingleton('customer/session')->getCustomer()->debug()
the only variable that is returned is the website_id.
有人知道我要做什么才能工作吗?
Does anyone know what I have to do in order to get this to work?
推荐答案
好的,看来我必须自己加载会话.我必须在函数中添加以下内容:
Ok it looks like I had to load up the session myself. I had to put the following in my functions:
Mage::getSingleton('core/session', array('name' => 'frontend'));
希望这会有所帮助.
这篇关于Magento网站的不同部分的客户会话是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!