Magento客户/会话无法正常工作 [英] Magento customer/session not working
问题描述
这个问题首先引起人们的注意,因为前端的订单历史记录页面(*/sales/order/history/)只是显示一条短消息:您没有下订单.
This problem first came into awareness as the order histories page (*/sales/order/history/) in frontend was displaying nothing but a short message: You have placed no orders.
经过一些调试后,发现问题出在此功能上:
After some debugging, it turns out the problem lies with this function:
Mage::getSingleton('customer/session')
除了网站ID外,它不返回包含当前客户信息的会话实体,这就是为什么订单集合在过滤了客户ID后返回空结果的原因.
It does not return a session entity containing current customer's information except the website id, which is why the order collection returns an empty result after filtering on the customer id.
实际上在Stack Overflow上有一篇文章讨论了类似的问题: > Magento的不同部分的客户会话是不同的网站 .但这并没有给出很好的解释.
There is actually a post on Stack Overflow discussing a similar problem: Customer session is different in different parts of a Magento website . But it has not given a good explaination.
令人困惑的是,就我的情况而言,该功能在某些部分运行良好,而在另一些部分则无法运行.例如,我插入
And what is confusing is that, with my case, the function works well in some parts but not the others. For example, I inserted
<?php echo var_export(Mage::getSingleton('customer/session')->getCustomerId(), true) ?>
进入目录产品列表模板,并在登录后显示客户ID.但是同一行在订单历史记录页面中返回Null.
into the catalog product list template, and it displays the customer id after login. But the same line returns Null in the order histories page.
我在app/code/core/Mage/Customer/Model/Session.php中找到了这些代码
I located these codes in app/code/core/Mage/Customer/Model/Session.php
public function getCustomer()
{
...
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
if ($this->getId()) {
$customer->load($this->getId());
}
$this->setCustomer($customer);
return $this->_customer;
}
设置网站ID后,它将根据$ this-> getId()加载客户实体.
After setting the website id, it loads the customer entity depending on $this->getId().
为什么客户会话实体的'id'属性并不总是有效?有人可以分享他的知识吗?非常感谢.
Why the 'id' attribute of customer session entity is not always valid? Can someone share his knowledge please. Many thanks.
推荐答案
有趣的是,当客户会话为空并且您正在访问历史记录时,为什么不将用户重定向到登录页面(客户/帐户/登录/)页.请验证是否已自定义Mage_Customer或Mage_Sales.
It's interesting why the user is not get redirected to the login page (customer/account/login/) when the customer session is empty and you are visiting the history page. Please verify if Mage_Customer or Mage_Sales were customized.
如果它被重写,它将是第一个检查的地方.
If it was rewritten this would be the first place to check.
这篇关于Magento客户/会话无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!