I would like to add a Block with different content when user is logged in or not. Content depends not on customer-data - just logged-in state.

class Grouped extends \Magento\GroupedProduct\Block\Product\View\Type\Grouped
    protected $customerSession;

    public function __construct(
       \Magento\Catalog\Block\Product\Context $context,
       \Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
       array $data,
       \Magento\Customer\Model\Session $customerSession
        $this->_isScopePrivate = true;
        parent::__construct($context, $arrayUtils, $data);
        $this->customerSession = $customerSession;

    public function isLoggedIn()
        return $this->customerSession->isLoggedIn();


In my phtml-File a just call $this->isLoggedIn() but it is always "false" when fullpage-cache is enabled.

How I could get information about customer-logged-in-state when fullpage cache is enabled on product-view page? How I prevent it from caching or adding two different caching-tags? (not-logged-in or logged-in) I believed in $this->_isScopePrivate but doesn't help..

Pricing, which depends on customer-group, works well on product-view page but don't find any informations why.

2 Answers 2


Sorry, answering myself is a little bit ridiculous.

getChackeKeyInfo is only relevant for block-caching, fullpage-caching looks different :(

In case of depending on Customer\Session isLoggedIn is always "false". Same when cache is clean before calling product-view.


Instead of depending on Customer\Session I copied some code auf Review Module. It depends on \Magento\Framework\App\Http\Context $httpContext.

In this case I'm able to distinguish logged in or not by calling


Would be great to get some explanation why :)

  • just curious: is a cache key change not working at all with fpc? Was hoping for some automatic hole punching, but did not look into this yet Mar 31, 2016 at 16:53
  • far shot on your question: I assume the http context considers a cookie set if the user is logged in Mar 31, 2016 at 17:00
  • cool decision. helped me alot
    – Anna
    Mar 3, 2017 at 15:48

the isScopePrivate switch sounds reasonable at first, but it seems not to be considered in the cache key generation: https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/View/Element/AbstractBlock.php#L967

adding the customer group to the cache key by overriding the getCacheKeyInfo method should do the trick in your case: https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/View/Element/AbstractBlock.php#L957

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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