After logging in as a customer, we noticed that the shopping cart was not displayed at all. It was only visible on the customer account page. Whether the cart was displayed or not was defined in the following file: C:\xampp_7_1_23\htdocs\oku-online\app\design\frontend\econcess\default\Magento_Checkout\templates\cart\minicart.phtml The if statement was:
$this->_objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) { }
To make it always valid, we added the condition || 1==1
$this->_objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()|| 1==1) {
}
So the problem is that the if statement does not work correctly on all pages. A possible solution can be found here: https://magento.stackexchange.com/questions/91897/how-to-check-if-customer-is-logged-in-or-not-in-magento-2
According to this thread, $customerSession->isLoggedIn()) should not be called directly. Instead, a helper needs to be created. For this purpose, we use an already existing helper, where we create a Data.php file at \app\code\Template-Name\Helper-Name\Helper\Data.php
We then add the following code:
<?php
namespace template-name\helper-name\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
/**
* Created by Carl Owens (
* Company: PartFire Ltd (www.partfire.co.uk)
**/
class Data extends AbstractHelper
{
/**
* @var \Magento\Framework\App\Http\Context
*/
private $httpContext;
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Http\Context $httpContext
) {
parent::__construct($context);
$this->httpContext = $httpContext;
}
public function isLoggedInEconcess()
{
$isLoggedIn = $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
return $isLoggedIn;
}
}
Then, in our minicart.phtml template, we reference the helper file and replace $customerSession->isLoggedIn with the helper function:
$customerSession->isLoggedIn :
$helperloggedin = $this->helper('Econcess\Mp4Allow\Helper\Data');
if ($helperloggedin->isLoggedInEconcess(){
