I want to get online or logged In customer collection list.
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.
-
-
-
-
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
-
To get logged in customer data in Magento 2,Refer here - https://meetanshi.com/blog/get-logged-in-customer-data-in-magento-2/
-
I want to logged In customer collection list. Not need customer data. – Masud Shaikh Apr 6 '20 at 8:09
-
Check this answer , if its relevant magento.stackexchange.com/questions/173530/… – Hamendra Sunthwal Apr 6 '20 at 8:14
-