-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to get customer data from customer session #2010
Comments
After some investigation we found that Magento/Customer/Model/Layout/DepersonalizePlugin.php::afterGenerateXml() is clearing the data from customer session when cache is enabled public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
{
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
$this->visitor->setSkipRequestLogging(true);
$this->visitor->unsetData();
$this->session->clearStorage();
$this->customerSession->clearStorage();
$this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
$this->customerSession->setCustomerGroupId($this->customerGroupId);
$this->customerSession->setCustomer($this->customerFactory->create()->setGroupId($this->customerGroupId));
}
return $result;
} |
Can this issue be closed? |
@bgkavinga and how did you fix your issue ? I have a similar problem with a block which needs customer information. Due to the plugin which depersonalize customer data in Customer Module, I cannot get the customer data when the cache is enabled. This depersonalizeChecker method is called before the block is instantiated. |
Looks like that you may find the answer here: http://magento.stackexchange.com/questions/86674/block-with-cachable-false-not-rendered-on-product-view-page/90130#90130 The block must not be in saved in cache (which is quite logic) however it must also be the property of the block must be set to |
@diglin My first solution was disable cache for that block in layout file. But it slows down the page load. When it comes to Varnish it always do esi update for that block. So I had to get customer session data directly from the $_SESSION until they come up with solution. May be this has been fixed in GA release. |
@bgkavinga thanks for your feedback. The solution from stack exchange worked for me. Do not forget to clean your cache. |
Any updates for this issue on latest magento2 version? I tried $_SESSION but its not working for category and product pages. |
I think this issue is directly related to #3572 |
It seems that this issue is still exist even in the 2.1.6. Any workaround is appreciated. |
Finally below workaround worked for me. (Clue from : #3294 post by @saravananvelu) |
[plankton] MAGETWO-86454: [Backport for 2.1.x] Update copyright year
That does not seem to be an issue since Magento 2 cleans the session storage for cacheable requests in order to avoid caching of customer private content. In short, you should not access the customer session data, while processing the GET request intended to render the cacheable page. |
As @dmytro-ch said you have to use a special Magento approach to work with the private content. Here is an example https://github.com/adnnor/customer-session-sections |
when cache is enabled and you have session->getCustomerId = null issue, you just need to add Factory pattern private SessionFactory $customerSessionFactory; construct(SessionFactory $customerSessionFactory) { public function someFunction() { |
@erikffflabel thanks for the tip, this helped me a lot! |
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
The text was updated successfully, but these errors were encountered: