1

I am trying to find out the session Id number.

I am using object manager for this (temporarily):

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerName = $customerSession->getCustomer()->getName();
?>
<div>Customer Session:<?php echo $customerSession->getCustomerId() ?></div>

Now, when I am logged in, the customer session display a number (expected behaviour), however, when I am logged out, there is no output.

My question is, should not-logged-in ("guest") customer have a session ID?

3

Hey in my knowledge guest customer(logout) don't have any customer id a guest customer have only guest id so when you are logout you can get guest id and when you are logging then only you get customer id.

  • hymmm, is there a session id for a guest customer? For example, if a guest customer place an order, they get assigned some kind of id? – Greg Sep 18 '18 at 15:35
  • No you can't have it. If customer placed an order as guest then you can have only their limited details like address, email id, phone number etc. Yes if you create new account of that customer during guest checkout then might be you can get customer id but once you placed order only then..... Please accept this answer if you find this reply helpful. – Shubham Khandelwal Sep 18 '18 at 15:44
  • Yes, I found my answer here :) thanks for your time ;) – Greg Sep 18 '18 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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