0

I am making this observer class to check if a visitor is logged in.

use Magento\Framework\Event\ObserverInterface; use Magento\Customer\Model\Session; class CheckLoginObserver implements ObserverInterface { /** * @var \Magento\Customer\Model\Session */ protected $customerSession; public function execute(\Magento\Framework\Event\Observer $observer) { //use $customerSession variable here ... } 

The goal is to use the $customerSession class in the execute function. What's the right way to do that?

1

1 Answer 1

1

It depends. Which event are You using for that observer? There is possibility that You can use customer session from Observer. Of course You can check it by look what contain $observer (by using xdebug).
If observer doesnt contain that, You have to use __construct function to load customerSession.

1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.