How to check if the customer is logged in or not via factory method ?

How to check if the customer is logged in or not via factory method ?

BLOCK file :

namespace Test\Module\Block;

class testing extends \Magento\Framework\View\Element\Template

{

protected $customerSession;

public function __construct(

\Magento\Framework\View\Element\Template\Context $context,

\Magento\Customer\Model\Session $customerSession

) {

$this->customerSession = $customerSession;

parent::__construct($context);

}

public function customerIsLogin()

{

return $customerSession->isLoggedIn()

}

}

PHTML file :

echo $this->customerIsLogin();

?>



Copyright © 2024 Tridhya Tech Limited, Inc. All rights reserved.