检查客户是否在线magento

时间:2012-12-14 13:55:23

标签: php magento

首先请原谅我,如果我的问题看起来有点过时但我会很感激,如果有人可以指出我正确的方向或样本或代码,可以通过编程方式在线获取所有当前登录的客户。

我已经发现你可以使用

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

查看当前用户是否已登录,但我要问的是检查特定用户在哪里,从他的身份知道他/她是否已登录。

我已经在magento论坛上发布了一个类似的问题,你知道但至少到目前为止还没有回复。通过此链接http://www.magentocommerce.com/boards/viewthread/300354/

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

3 个答案:

答案 0 :(得分: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()是否为1。

答案 1 :(得分:0)

答案 2 :(得分: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);
相关问题