1

So, I followed the steps in the 2nd answer (by Miroslav Petroff) on this question: How can i check whether user is logged in or not in magento 2.0

The if statement only works correctly when viewing pages like Wishlist, My Account, Cart, etc. Currently on the Homepage, Catalog pages, Product pages, and possibly others, my if statement is returning 'not-logged-in'.

if ( $helper->isLoggedIn() ):
echo ' logged-in';
else:
echo ' not-logged-in';
endif;

Anyone ideas what might make these pages return different results?

1

I ended up using this answer and now the if statement returns the correct value on all pages.

https://magento.stackexchange.com/a/108478/40091

Everyone says not to call the ObjectManager directly, but sometimes you gotta live life on the edge.

|improve this answer|||||
0

Try this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');

if($customerSession->isLoggedIn()) 
{
// your code
}
|improve this answer|||||

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