我想获取我的客户的最后登录日期(在Magento上)。
我这样做:
$customer = Mage::getSingleton('customer/session')->getCustomer();
$logCustomer = Mage::getModel('log/customer')->load($customer->getId());
$lastVisited = $logCustomer->getLastVisitAt();
但它不起作用,结果是空
我的数据库中有一个名为"customer_log"的表,这个表是空的!此表包含以下列:"customer_id"和"login_at"。
您知道我是否必须在后台激活一个选项才能使其工作吗?
谢谢,对不起我的英语不好。
您的表customer_log
不会出现在我的Magento 1.3.2安装中,但是有一个log_customer
表。它有log_id, visitor_id, customer_id, login_at, logout_at, and store_id
列。login_at
列将为您提供所需的内容。
// $lastVisited = $logCustomer->getLastVisitAt();
// becomes
$lastVisited = $logCustomer->getLoginAt();
这将以UTC格式返回MySQL datetime
(如2012-06-17 13:45:57
),还有一个您可能更喜欢返回Unix时间戳的getLoginAtTimestamp()
方法。
对我来说,这是最好的方法:
$customer = Mage::getSingleton('customer/session')->getCustomer();
$logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer);
$lastVisited = $logCustomer->getLoginAtTimestamp();
$lastVisited = date('Y-m-d H:i:s', $lastVisited);