Skip to content

Unable to get customer data from customer session #2010

Closed
@bgkavinga

Description

@bgkavinga

I have DI in constructor to inject customer session to my class \Magento\Customer\Model\Session $customerSession, But the injected session object does not contain customer id or customer reference.I also checked the injected session on Magento\Catalog\Block\Product\View it also does not contain customer id or reference

public function __construct(
        TemplateContext $context,
        Session $customerSession,
        CustomerRepositoryInterface $customerRepository,
        HttpContext $httpContext,
        array $data = []
    ) {
        $this->customerSession = $customerSession;
        $this->customerRepository = $customerRepository;
        $this->httpContext = $httpContext;
        $this->scopeConfig = $context->getScopeConfig();
        parent::__construct($context, $data);

        // customer session does not contain customer data
        $cid=$this->customerSession->getId(); // returns null
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions