2

首先,如果我的问题似乎有点离题,请原谅我,但如果有人能指出正确的方向或可以通过编程方式让所有当前登录的客户在线的示例或代码,我将不胜感激。

我已经发现你可以使用

Mage::getSingleton( 'customer/session' )->isLoggedIn()

查明当前用户是否已登录,但我要问的是从他的 id 检查其他特定用户,以了解他/她是否已登录。

我已经在magento论坛上发布了一个类似的问题,以防你发现但至少在这篇文章发布之前还没有回复。通过此链接http://www.magentocommerce.com/boards/viewthread/300354/

任何帮助表示赞赏。提前致谢。

4

3 回答 3

3

如果我对您的理解正确,您想知道当前登录的每个客户,这段代码(来自Mage_Adminhtml_Block_Customer_Online_Grid)应该这样做:

    $collection = Mage::getModel('log/visitor_online')
        ->prepare()
        ->getCollection();
    /* @var $collection Mage_Log_Model_Mysql4_Visitor_Online_Collection */
    $collection->addFieldToFilter('customer_id', array('notnull' => true))->addCustomerData();

如果要检查特定用户,请替换array('notnull' => true)为此客户的 id 并检查count()集合的 id 是否为 1。

于 2012-12-14T15:13:09.430 回答
0

参考https://github.com/benmarks/magento-mirror/blob/1.7.0.2/app/code/core/Mage/Customer/Model/Session.php#L140

Mage::getSingleton( 'customer/session' )->getCustomerId();
于 2012-12-14T14:45:47.690 回答
0

老问题...无论如何,我认为检查单个用户是否在线的最佳方法是从app/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php. 以下行取自该文件的不同部分。基本上,我们利用Mage_Log_Model_CustomerMage_Log_Model_Visitor模型检查注销和上次访问时间。

$id = "<CUSTOMER_ID>";
// Here make your tests about the ID, if the user exists, etc...
$customerLog = Mage::getModel('log/customer')->loadByCustomer($id);
return !($customerLog->getLogoutAt() ||
    strtotime(now())-strtotime($customerLog->getLastVisitAt())>Mage_Log_Model_Visitor::getOnlineMinutesInterval()*60);
于 2016-12-01T18:49:05.210 回答