0

I want to get online or logged In customer collection list.

2

Use this below code for get online customer list :

Way 1 :

protected $onlineColl;

public function __construct(
    \Magento\Customer\Model\ResourceModel\Online\Grid\CollectionFactory $onlineCollFactory
){
    $this->onlineCollFactory = $onlineCollFactory;
}

public function yourFunction()
{
    $customerSession = $this->onlineCollFactory->create();
    echo "<pre/>";
    print_r($customerSession->getData());
    exit;
}

Way 2 :

        $om = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession = $om->create('Magento\Customer\Model\ResourceModel\Online\Grid\Collection');
        $customerData = $customerSession->getData();
        echo "<pre/>";
        print_r($customerData);
        exit;

Remove generated and clean cache.

9
  • I will check and update you soon. Thanks! – Masud Shaikh Apr 6 '20 at 12:03
  • Okay. Is it done? – Rohan Hapani Apr 7 '20 at 4:17
  • It is working fine but i want to show registered customer only. – Masud Shaikh Apr 7 '20 at 7:20
  • Please check the screenshot prnt.sc/ruitwk. If i have logout then customer should be not show in the list. – Masud Shaikh Apr 7 '20 at 7:21
  • How to show registered online user only? – Masud Shaikh Apr 7 '20 at 7:40
0

To get logged in customer data in Magento 2,Refer here - https://meetanshi.com/blog/get-logged-in-customer-data-in-magento-2/

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.