This is in reference to Magento 2.4.6
2.\Magento\Customer\Model\Session does not work on product detail page
Say you have a viewModel where you need to check if the customer is logged in or not.
If vendor/magento/module-customer/Model/Layout/DepersonalizePlugin.php is executed before your viewModel it is most likely that the session details are reset.
Best option is to use
protected $httpContext;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\Http\Context $httpContext,
array $data = []
) {
$this->httpContext = $httpContext;
parent::__construct($context, $data);
}
public function getCustomerIsLoggedIn()
{
return (bool)$this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
}
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)