-
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
Cannot get customer session data #3294
Comments
Internal ticket ID MAGETWO-49202 |
I can confirm this bug, when I'm logged in fronted When I use this :
My return is false... But, when I used this, it's work fine :
|
Experiencing the same problem. |
Experiencing the same problem on version 2.0.2. |
Related to #3572 |
Experiencing the same problem on version 2.0.8. The session object disappeared sometimes. Need to disable the cache to make it work. |
I have installed Magento 2.1.1 latest version still facing this issue which is not able to retrieve customer data from session in product view page, when cache is enabled |
Also bug in Magento 2.1. I think it's related issue: |
$ObjectManager= \Magento\Framework\App\ObjectManager::getInstance(); This thing worked for checking customer is logged in or not when page cache is enable |
Hi @KalaiarasanSeetharaman, |
First of all I also would consider this a bug as it is really annoying and therefore should be fixed / handled better imho. However I doubt the Mage Devs see it as bug as they always declare the code parts were they use We came across this problem in a custom block and could "fix" it easily be also declaring it as not cacheable in its layout config XML. So instead of @deepanshu27193 |
@tehXor and yes regarding your cacheable suggestion, i have one point, |
I have tried like this and got the customer session object when the cache is enabled.
|
@tehXor Thanks for the tip on flagging the layout as cachable=false. That worked like a charm for me! |
To all the people here suggesting to mark a block as non-cacheable: keep in mind that one non-cacheable block in a layout will make the entire layout non-cacheable (talking about full page cache here). The consequence is that the page in question will never be cached by the FPC, and if your non-cacheable block happens to be in a page header/footer that you use on all your pages, then full-page caching will be completely broken for your entire website. That is a big performance price to pay. |
@pantaoran have you come up with a solution around this? I haven't been to get anything to work. I almost got using SessionFactory to work, but it kept sending back the same session values even after I called session->setdata with new values. |
@jstrez77 I'm not sure what exactly you're trying to solve. What I described in my last comment is exactly what happened to me until I realized how much worse I made it. I'm now trying to fix it, and it seems that the solution is to load user-specific data through javascript instead of php, this way the server page can still be cached and the client will still see relevant info for their account. First I though that would have to be AJAX, but actually Magento already loads a bunch of data that you can just access without further calls to the server. Look at the example at https://github.com/magento/magento2/blob/develop/app/code/Magento/Theme/view/frontend/templates/html/header.phtml Also, what helped me a lot in understanding all this is: https://inviqa.com/blog/how-full-page-cache-works-magento-2 |
See customerSessionFactory for fix above- it doesn't contain full customer data but the ID is there - you can. manually l load customer object after grabbing the ID! |
This is NOT a problem in full page cache. It is supposed to work this way saving all necessary data in See http://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching/public-content.html#configure-page-variations for details. @Nuranto, http://devdocs.magento.com/guides/v2.1/extension-dev-guide/cache/page-caching/private-content.html explains how to pass customer-specific data properly. |
@orlangur What have we to do to retrieve customer's email for logged user with FPC enabled? It is absurd that there is no easy way to do so. |
Well, Magento2 still has Zend framework 1 and prototype.js inside. In 2017. What's your point? :D
Well how would you expect extension and integrator developers to care about it, if it's not even done for the core yet? Looks like double standards to me. I really hope the blocks cache\tags\variations\local storage system becomes the center of Magento 2's frontend fireworks. But I just don't see right now how could the outside developers transition to it en masse while it's still such a work in progress. Maybe, some other day :) |
ZF1 is in process of elimination and some reminants of
It was done for crucial pages, sometimes regressions happened like review block on product page, some third-party developers may be unaware and accidentally make such pages uncacheable :( That's why such ajaxified FPC need to be completely eliminated for good. |
You can try by creating an object of objectManager and should not use objectManager directly. Use something like,
|
@kazimnoorani8704 this is still using |
Fixed issues: - MAGETWO-92170: Redundant File Names for Quote Attachments - MAGETWO-90725: Wrong session messages behavior - MAGETWO-94173: Disable backups by default
How i got it $objectManager = '\Magento\Framework\App\ObjectManager'::getInstance(); now $isLoggedIn will give us weather customer is logged in or not and then to get customer information |
For me the session factory made the difference.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Thank you for your contributions. |
A little late to the party, but found what appears to be a good solution, at least for me. Instead of using Magento\Customer\Model\Session, try calling 'isLoggedIn()' on Magento\Customer\Block\Account\AuthorizationLink. I had header-related issues (on homepage specifically) and this change solved it for me. |
So somewhat reason, Customer Session is modified by other functions before.
It won't work if we get already an instance one. GET
And use an instance from Constructor as well. By default, Object Manager will use GET function to inject an instance. So I think Magento should fix it. It takes resources when we create a new more one for a class. |
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() { that is very good solution for this issue :) |
Event :
catalog_product_get_final_price
I need the current logged in customer id.
On Observer :
=>
But I'm logged in in front, this is confirmed when using
$this->_httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH)
:Is this a bug ? Or am I wrong somewhere ?
(Note : if I dump
$_SESSION
, customer_id isNULL
too :()The text was updated successfully, but these errors were encountered: