app/code/Vendore/Module/Block
<?php
namespace Vendor\Module\Block;
class CustomerLink extends \Magento\Framework\View\Element\Template
{
protected $_customersession;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Customer\Model\Session $session
) {
parent::__construct($context);
$this->_customersession=$session;
}
public function sessionCheck()
{
return $this->_customersession->isLoggedIn();
}
}
app/code/Vendore/Module/view/frontend/template
<?php
if($block->sessionCheck())
{
echo 'logged in';
}
else
{
echo 'logged out';
}
?>
It works only in customer page and checkout/cart page, remaining page it return false even customer logged in.
so I decided to use \Magento\Framework\App\Http\Context $httpContext
this return right boolean value in entire website but how to get customer details using httpContext
.
why \Magento\Customer\Model\Session is only working in customer page?
note: all caches are in enable mode.