Magento2: Problem reading session file

Created on 29 Feb 2016  路  89Comments  路  Source: magento/magento2

I'm getting a weird behavior using Magento 2.0.2, it's described here as steps:

  1. On 'Sign in' front page, as customer if I type a wrong username/password I get redirected to the same page (normal) but Magento doesn't display any error message (abnormal), I was expecting "Invalid login or password" from LoginPost.php . Taking a look to the proper session file in var/session/sess_###, the error is stored there...
  2. I login again with the correct password and get redirected to my dashboard (normal) but the customer's name doesn't appear in the top menu bar, as a part of the welcome message (abnormal). Also, if the customer had in his car items from a previuos session, the orange square to the right of the cart icon doesn't show any amount.
  3. Then, if I add any item to the cart I get the message 'You added xxx to your shopping cart' (normal) but not only this but also I get the previous 'Invalid login' message (abnormal).
  4. After this, if I click on the cart icon and 'Go to Checkout' button, I get the login popup (abnormal) instead of going to the onepage checkout (normal).
  5. Finally, if at this point I go back to 'My Account', I get the proper customer name in the top bar, with the proper amount of items in the cart and I can go to checkout as if nothing had happened.

I'm working on customize Magento for specific needs, I added a field to customer_entity table, 'mobile' field which has the same attributes as 'email' field. I disabled email as requiered field in the database. I added three custom fields stored in customer_entity_varchar. I had preferences of many files of Magento/Customer module. Even if I disable all my modules, rollback all my commits, clearing cache, var/generation, var/session and puc/static/frontend/*, I'm still getting this behavior. I have two instances, one running in production mode and one as developer, both has the same behavior.
I'm using Opera, Firefox and Chrome for the tests, clearing the browser history and cache makes no difference.

Also, I get this messages in the system.log file:

[2016-02-29 07:05:45] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_2c7461af04bb11fe209659d7147d2c579: Please correct the XML data and try again. [] []
[2016-02-29 07:05:45] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_20a98983867a1770682b48d9a0ad63441: Please correct the XML data and try again. [] []
[2016-02-29 07:05:45] main.CRITICAL: Broken reference: the 'catalog.compare.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-02-29 07:05:45] main.CRITICAL: Broken reference: the 'sale.reorder.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-02-29 07:05:45] main.CRITICAL: Broken reference: the 'wishlist_sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-02-29 07:05:45] main.CRITICAL: Broken reference: the 'paypal.partner.right.logo' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-02-29 07:05:45] main.CRITICAL: Broken reference: the 'bml.right.logo' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2016-02-29 07:05:45] main.CRITICAL: Broken reference: the 'store.settings.currency' tries to reorder itself towards 'store_language', but their parents are different: 'store.settings' and 'header.panel' respectively. [] []
[2016-02-29 07:05:45] main.INFO: Cache file with merged layout: LAYOUT_frontend_STORE1_26f1b068ec7ccf4878f9284dd1137afd1: Please correct the XML data and try again. [] []

Sometimes, for an unknown reason the error disappear and the users can login and go to checkout normally. But this error is getting more persistent since 5 days ago.

Any advice to fix it? Thank you so much!

EDIT:
I must add something I read from a different issue: I also see the red/orange square next to the cart icon but empty, before and after login, only shows an amount after add something to the cart and adds this new item to those added in previous sessions.

UPDATE:

  • For the error messages, on 'Sign in' frontpage, I realize that the object 'messages' inside "Magento/Theme/view/frontend/web/js/view/messages.js" is not getting populated.
  • For the step (3) after adding a product, there is a call to "http://my.magento2.server/index.php/customer/section/load/?sections=compare-products%2Ccustomer%2Cwishlist%2Clast-ordered-items&update_section_id=false" which renders back the products in the cart and also the messages stored in the session file. I think is because it triggers the event listener "$(document).on('ajaxComplete', function (event, xhr, settings) " inside "Magento/Customer/view/frontend/web/js/customer-data.js" which update the content of the sections with the result of previous call to "section/load/?..." .
  • For step (5), customer data comes from a call to "$(document).on('ajaxComplete', function (event, xhr, settings)". I saw this function is called on every section, but don't understand why on 'Sign in' page and after login it retrieves empty objects.

After step (5) take place, every access to magento site (e.g. in the browser, if I close the tab and reopen it from index.php or any other section of the store) is rendering correctly the customer name on top bar and items in the cart.

Ready for Work needs update bug report

Most helpful comment

Hey Guys,

I have found a temporary solution:

To solve cart count/content update issue modify below file:
vendor/magento/module-customer/view/frontend/web/js/customer-data.js

find this line: privateContent = $.cookieStorage.get('private_content_version');

and add below code :

// To load all msg & cart update ajax on page load var reloadsections = ['cart','messages']; this.reload(reloadsections,true);

After adding above lines your function looks like below:

var customerData = {
        init: function() {
            var countryData,
                privateContent = $.cookieStorage.get('private_content_version');

            // To load all msg & cart update ajax on page load
            var reloadsections = ['cart','messages'];
            this.reload(reloadsections,true);

            if (_.isEmpty(storage.keys())) {
                if (!_.isEmpty(privateContent)) {
                    this.reload([], false);
                }
            } else if (this.needReload()) { ...........

Please test the changes on your code, and confirm if it is working. This is very temporary solution.

All 89 comments

I also see this behavior, and it's really worrying me because as long as this persists I cannot possibly put any site live!

Same issues here and only after upgrading from 2.0.0. to 2.0.2.

@bb8d clearing cookies should be performed after upgrading. @sengaigibon there are two internal tickets that should solve your problem and will be delivered soon (MAGETWO-46014 and MAGETWO-49449)

@sevos1984 cookies and local storage was cleaned.

Now I noticed two more issues, one is kind of the opposite of this one: I'm adding custom fields to the address, then in the checkout step 1, after I update the page pressing F5 suddenly I see a page telling me I have no items in my cart, customer name in the top menu bar, item amount in the orange square. If I click into My Account I get redirected to Sign in page... Should I open a new issue describing all the details?
The other thing I saw is after update the page in checkout step 1, the country in my already stored addresses disappear, and reappear after I cleaned var/session/*, browser cookies and log in again.

@sevos1984 Great! Thanks! :+1:

@sengaigibon Check that your system permissions set correctly http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html, also try clearing everything in var folder.

I found that if I clean var/session* but don't clean browser cookies is when I get the behavior of the last comment with the customer name in the bar but logged out.

@sevos1984 what is the status on those MAGETWO-46014 and MAGETWO-49449? Also, will this lead to a new release or will I need to use the dev branch to get it fixed?
Or maybe I should direct this question to @slavvka since it was assigned to him?

Another week has gone by, so I'm going to ask again: Is this fixed now @sevos1984 and @slavvka ?
On the develop branch I see some commits regarding MAGETWO-49449, but MAGETWO-46014 is never mentioned so far.

We'd really like to show Magento2 in client meetings, but as long as a simple customer login doesn't work properly we just can't do that.

@bb8d can you share with us some details about your installation environment? such as operating system, running a virtual machine or containers? any special software running on your Magento instance? Thanks!

Sure:

OS: Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux (debian 8.2 - jessie)
MYSQL: Ver 14.14 Distrib 5.7.10, for Linux (x86_64) using EditLine wrapper
PHP 5.6.14-0+deb8u1 (fpm) with with Zend OPcache v7.0.6-dev
WEBSERVER: nginx/1.8.0
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1k 8 Jan 2015
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed' --with-ipv6

MAGETWO-46014 is regarding delayed messages and will be delivered later, @pantaoran @bb8d I can't recreate your problem, looks like some issues with your environment

@sevos1984 what does that mean "MAGETWO-46014 will be delivered later"? How much later?

Regarding environment, I'm running this in Docker containers, so there isn't necessarily a single one OS, but all the official containers run debian 8 (jessie).

nginx: https://hub.docker.com/_/nginx/ (I'm using the nginx:1.9 image, version output says nginx/1.9.10)
php-fpm: https://hub.docker.com/_/php/ (I'm using the php:7.0-fpm image but I also tried php:5.6-fpm, version output says PHP 5.6.17)
mysql: https://hub.docker.com/_/mariadb/ (I'm using the mariadb:10.0 image, version output says Ver 15.1 Distrib 10.0.23-MariaDB)

edit: added full php config details

@pantaoran later after release. I have nginx1.8.1 and php7.0.6-dev. I see you don't have bcmath extension that is required.

The same weird behaviour as @sengaigibon mentioned, here on Magento 2.0.4.
How Reproducible: Always.

@sevos1984 thanks for this info. According to the official documentation, bcmath is only required for the enterprise edition, and I'm using the CE and the readiness check at installation said that I had everything I needed.

@sengaigibon , @devhn , @moe-kayali , I was able to get this to work now and want to share my observations. It appears to have something to do with the used OS.

I previously noticed that the problem didn't appear on my Ubuntu-based development machine, but on my Debian server it failed as described. This is despite the fact that I'm running it all in docker containers, which should abstract away the host OS for all I know, but that doesn't seem to be happening. All my containers were using the official images as detailed in my last comment, and those are all Debian-based. So Debian containers on Ubuntu host worked, but Debian containers on Debian host didn't work.

I now created my own php and nginx containers to replace the official ones, and mine are based on Ubuntu. Lo and behold, this now works. Ubuntu containers work on Ubuntu host and on Debian host, the problem is gone.

All this is of course way too little data to be sure that this is the real reason, but my problem seems solved for now so I won't invest any more time. I guess the Magento team wasn't kidding when they state that Ubuntu is the supported OS.

I'm back again to report more problems.

The issue doesn't happen on my desktop anymore, but now I started testing mobile clients and here it's still the same behavior as described above, after logging in I see the "My Account" page but without my name in the menu, and when I try to checkout it says I'm not logged in.

It happens consistently on my android phone in firefox and chrome, and also on an iphone's safari. On desktop it never happens, regardless if I enable "device mode" to simulate mobile clients or not.

The mystery continues, guess my previous theory isn't that credible anymore :-(

I believe I am having the same issue on 2 different sites as well.

I am getting session issues on staging server. Like not getting current page, customer data etc from the session object.
The same thing is working perfect on local. I debugged a lot but no luck. Please help!

The issue was because of full page cache. After disabling, session is working fine.

I can reproduce the bug, if is it useful I can post the code.

I have full page cache turned off and still having the issue. I even rebuilt the site thinking the composer install was the issue, it is the same with a downloaded zip install.

Any update on this issue, I am on an Ubuntu 14.04 and am having the same issue. Cart won't update selected and even though guest checkout is enabled I get a popup to sign or register to checkout. I believe it has something to do with the sessions but have exhausted all avenues there.

In my case i solve the problem activating Varnish Caching.
Go to Stores -> Configuration -> System -> Full Page Cache, select Varnish Caching, and follow the instructions for configure/install Varnish.

I installed varnish and am still having the issue. Could it be possibly be related to this problem http://alanstorm.com/magento_sessions_early is there any way to check to see if the sessions are being set correctly?

@josegreyes If you look into %magento root folder%/var/sessions you'll find the files used to store the data for specific sessions. Delete everything there, open Magento, login, and if you look into the session file recently created, and your customer already had items in his cart, the file will show it with all the relevant info related to him. Also, in the web browser see that on every Magento page request there is a form_key attached to it, and you can check that is the same stored in the session file...
Btw, interesting what Alan Storm said, but was for a different Magento version

@sengaigibon hi there, i did what you said and i saw the session file created, but the form key does not match what is on the site. Also, each time I go to a different page, a new session file is created, I am thinking that is probably not right either. Thanks for your help!

@josegreyes For me, when I wrote last comment I had sess_87xxx file, and now I updated the page and navigate here and there, that file doesn't exist anymore, now is sess_aaxxx but with the same form_key, also for each time I navigate between pages, but I'm not using Varnish Caching, actually I have all cache disabled. But only one session file... Not sure what's happening :-/

Hi @sengaigibon, the fix for MAGETWO-46014 has been delivered to mainline. See commits 541ec80, 55a6e51, b4d3739, eec31f6, af2a832, d97ebe5, 3120b1e and 66e6ad6. If this issue is still reproducible please reopen it

hey,

any solution for that?
I have same problem

This issue is still reproducible in magento 2.1.0-rc1, 2.0.7, 2.0.6, and lower versions.
You can reproduce the bug in the following way:

1) Install a magento 2.1.0-rc1 or a lower version

2) Change deploy mode to developer:
php bin/magento deploy:mode:set developer

3) Download and install this module:
Test.zip

4) Make sure all cache types are enabled

5) Go to home page, under the LUMA logo you can see
"Session status: "
The ReadSession.php Block will execute the following code:
$session=$this->_session; $session->start(); return $session->getMessage();
The template read-session.phtml will execute:
Session status: <?php echo $block->readSession();

6) Go to page "setsession/save", if your magento installation folder is magento21 follow this link http://localhost/magento21/setsession/save
The module will execute the following code:
$session=$this->_objectManager->get('\Magento\Framework\Session\SessionManagerInterface'); $session->start(); $session->setMessage('The session works');
You can see under the LUMA Logo:
"Session status: The session works"

7) Go to home page, under the LUMA logo you can see (the bug ):
"Session status: "
When the session works you can see: "Session status: The session works"

8) In home page go to search box, digit something and press enter, you can see: "Session status: The session works"
In this case form some unknown reason the session works

9) Disable Full Page Cache

10) Clear all cache type

11) Go to page "setsession/save"

12) Go to home page, now the session works so you can see:
"Session status: The session works"

But what is solution?

This issue is still reproducible in Magento 2.0.7. Actually, I faced to this issue in Magento 2.0.5 but after upgrading to 2.0.6, it worked fine. Now after upgrading to 2.0.7, this issue comes back...

Could anyone find solution to this issue?

In version 2.0.6, it's working fine :)

I tried 2.0.4, 2.0.6 and 2.0.7 all, but its still not working. If there is special patch in 2.0.6 please let us know.

No its not working in 2.0.6 as well. Checked twice.

Ok, We have resolved the issue...To update minicart on every action we have to update "vendor/magento/module-theme/etc/frontend/sections.xml" file. This updates "messages" section on every action.

Adding <section name="cart"/> on line no.12 will reload the cart on every action.

This worked for us.

The message transport mechanism has been changed from customer data to cookies in 2.0.8 so most probably this problem will disappear in that version.

@slavvka you say it will switch mechanism in 2.0.8. Will that also be included in 2.1.0? I see some people above saying that this still happens in 2.1.0-rc1.
Also, when will 2.0.8 come out?

@pantaoran Yes, it is included in 2.1.0. Unfortunately I don't know the date of 2.0.8 release

I kind have the same issue.

I found that my issue is in customer-data.js.

line 18 :

var storage = $.initNamespaceStorage('mage-cache-storage').localStorage;

The var storage got keys. The keys should be an array of the sections which must be reloaded with AJAX.

So the keys are an array like ["customer", "compare-products", "last-ordered-items", "cart", "directory-data", "review", "wishlist"]
And then the AJAX request like http://mydomain.com/customer/section/load/?sections=&update_section_id=false&_=1466686334395

But the fact is storage.keys() is empty and the AJAX request doesn't exist. Do you, guys, have the same behaviour ? Do you know how to fix it ?

Thanks,

_Magento ver. 2.0.2_

We were having the same issue that Pigau is describing on Centos 6.5. We moved the installation to a Centos 7.2 instance and the error disappeared and started working as expected. We also tried it on an Ubuntu 14.04 machine and it worked there as well, no change to the code were required.

@slavvka Due to the comments about this bug is still happening I want to re-open this issue but I couldn't find where or how... thanks

@Pigau ,this is related to cookies, the key do not get created if you are using private browser. Please check once in regular browser.

@josegreyes , OS should not make any difference to the code. Please check the PHP version that might be helping you solve the issue.

@sengaigibon Due to comments above the bug is still happening on old Magento code (2.0.2, 2.0.6) but as I wrote previously it may work in the latest code (develop, 2.1.0, and 2.08 that is coming soon)

Hello guys,

@100php, on my dev environment, I tried on :

  • Chrome Version 49.0.2623.75 (64-bit) on Ubuntu 14.04, in regular mode
  • Firefox 47.0 on Ubuntu 14.04, in regular mode

On the remote server, it is a debian 7 and I use the same browsers. The problem is still here.

@slavvka, as I can't upgrade the Magento version right now, what do think I can do ?

Edit : @slavvka I updated to 2.1.0, it didn't change anything. And now I have some errors on the code, so I'll go back to another version, maybe 2.0.6.

@Pigau have you tried the solution from @100php with <section name="cart"/>?

@slavvka I tried adding a sections.xml in app/design/frontend/mynamespace/mytheme/etc/frontend/
Is it the good place ?

And my sections.xml looks like :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="*">
        <section name="cart"/>
        <section name="checkout-data"/>
        <section name="customer"/>
        <section name="messages"/>
    </action>
</config>

I see. The internal ticket MAGETWO-54758 has been created.

Hello @slavvka, do you have more information about this ticket ?

@slavvka any news? same issue here on version 2.0.7.

I read all the informations and tried every possible solution but none of them worked.

Any news on the new release?

Thanks

Sorry guys, not yet

This is issue is now taking way too long, it has been more then 6 months ago that this occurred, still we did not find the key angle why the session file issue exists and comes back to part of the community.

@slavvka @sengaigibon @pantaoran @devhn @sevos1984 @moe-kayali @100php @sevos1984 @OgreMHDW @carmelomtb @sunilit42 @davidnguyen2205 @Pigau , can every one of you share it's local and test server setup in order to get an overview about differences in operating system & server / dev setup.

This would include:

  • Use of containerisation - Docker - CoreOS - other virtualisation tools
  • IF, containerisation which OS used to run containers + linux distribution inside containers - Linux OS + version
  • Linux OS - distribution version (on development + test server environment)
  • Web Server Software - Apache - NginX
  • PHP version - 5.6 - 5.6fpm - 7.0x
  • Dbase software & version - MySQL - MariaDB
  • Permission schemes for directory & files
  • The overall Server setup - separated Web + Database Cloud
  • Any use or activation of Redis / Varnish
  • Any other tools

@josegreyes, your case is very interesting and could help other developers. On top of using CentOS 7.2 / Ubuntu 14.04 could share the above setup

We were having the same issue that Pigau is describing on Centos 6.5. We moved the installation to a Centos 7.2 instance and the error disappeared and started working as expected. We also tried it on an Ubuntu 14.04 machine and it worked there as well, no change to the code were

required.

@slavvka can you share the current setups used for development and server setups by the core Magento 2 team. Preferably in a step by step guide which procedures will be done in order to setup a local and server

As the server requirements & server setup in the current online documentation are very limited

@all let's work together on this to get Magento 2 into production and prevent this bug in the future

After I tested with many versions (2.0.0 - 2.0.2 - 2.0.6 - 2.0.7 -2.1.0dev-branch - 2.1.0 GA) in the same way with Ubuntu 14.04 + PHP 7 + MySQL 5.6, I got this problem with some versions ( 2.0.0 - 2.0.2 - 2.0.7 - 2.1.0dev-branch ). I don't know how the versions (2.0.6 + 2.1.0 GA) worked well...

@davidnguyen2205 thanks David, did you use Apache or NginX - which versions?

I am using Nginx 1.10.1

@slavvka @sengaigibon @pantaoran @devhn @sevos1984 @moe-kayali @100php @sevos1984 @OgreMHDW @carmelomtb @sunilit42 @davidnguyen2205 @Pigau , are you all using NginX?

Yes, nginx 1.8.0

Yes

Nop, I'm using Apache/2.4.10 on a debian in a LXC.

Hello...

I am experiencing the same problems for a while.
Recently I updated the version of Magento to 2.1 but there the problem still exists.

I am using a development environment on windows7 with the following settings:
- WAMP 3.0.4
- Apache 2.4.17
- PHP 7.0.7
- Mysql 5.7.9

After some testing I see three (related) problems:

  • After login username most of the time not visible
  • After login sometimes it shows that I am not logged in until many page reloads
  • Minicart count is not always updated/shown
    --- After login previous items not shown until adding new product
    --- Before login sometimes cart already contains an item without adding one

Some more details:
When the cart items are not visible and the same for the username the data is missing in the call:
customer/section/load/?sections=&update_section_id=false&_=1468484020001

  • For the cart the summary_count variable is empty
  • For the customer the fullname and firstname are empty

@carmelomtb, the issue you described isn't a bug since you created a block which is cached by default. You should have added cacheable="false" to block definition in default.xml layout file.

Guys, I have rechecked the problem with messages again and couldn't reproduce it. I do state that in 2.1.0 and in 2.0.8 (that is coming soon) the transport of messages was moved from session to cookies to make them show faster so messages should appear anyway.

Unfortunately we also couldn't reproduce the issue with not displaying of customer specific data. Could you please provide us an image of environment the issue is permanently reproducible on? It would help us investigate it in vitro.

Hello, I have found one cause for the two problems below:

  • For the cart the summary_count variable is empty
  • For the customer the fullname and firstname are empty

When using Google Chrome in "private browsing" state, no data is saved to the local storage therefore the needed data is not available for Magento. In this situation you will never see cart count and username.

But it still does occur in normal browsing state to but less often.

@slavvka I got permission from my bosses to share our code/settings/environment with you for best possible cooperation on this problem. Please reach out to me by mail at [edited out] and I will see if I can supply you with anything useful.

Just to report back on my current status for everyone: I've upgraded to Magento 2.1.0 pretty much right after it came out, but I still see these session problems.

It's tricky because even after all this time I don't know a reliable way to always reproduce it. Not all users of my system see the problem, but some do.

Problem of reading customer name still exists in Magento CE 2.1.0. It works in firefox[notrmal mode] but not in chrome[latest version].

It is not browser-dependent. I did some more debugging on 2.1.0 just now and it looks like it's all about the presence/absence of a cookie with name(key)="section_data_ids". When the cookie is there, everything works fine. When I delete all cookies in my browser then the problem appears; even after customer login I cannot go to the checkout. That cookie does not get recreated, or at least not always.

@slavvka for reproducing the described problem, please check if deleting that cookie will lead to the expected result. Probably you need to find out why that cookie doesn't get set under some circumstances...

My Debug

I think it comes down to this comment. https://github.com/magento/magento2/issues/3357#issuecomment-225969037
The problem is described in the issue https://github.com/magento/magento2/issues/3357 is actually related to the cookie 'private_content_version'. This cookie doesn't set for some reason unless we enable full page cache[FPC] as mentioned in the comment.

Once we set FPC, everything is working fine and fast. But during the development its really a big issue. We cant set FPC and problem persist.

Cookie check happens here: /Magento_Customer/js/customer-data.js line number 192 in init() function.


http://magento.stackexchange.com/questions/112557/magento-2-minicart-welcome-message-other-do-not-work-with-page-cache-disabled

Hey Guys,

I have found a temporary solution:

To solve cart count/content update issue modify below file:
vendor/magento/module-customer/view/frontend/web/js/customer-data.js

find this line: privateContent = $.cookieStorage.get('private_content_version');

and add below code :

// To load all msg & cart update ajax on page load var reloadsections = ['cart','messages']; this.reload(reloadsections,true);

After adding above lines your function looks like below:

var customerData = {
        init: function() {
            var countryData,
                privateContent = $.cookieStorage.get('private_content_version');

            // To load all msg & cart update ajax on page load
            var reloadsections = ['cart','messages'];
            this.reload(reloadsections,true);

            if (_.isEmpty(storage.keys())) {
                if (!_.isEmpty(privateContent)) {
                    this.reload([], false);
                }
            } else if (this.needReload()) { ...........

Please test the changes on your code, and confirm if it is working. This is very temporary solution.

The comment from @sky4git is interesting and helped me a little bit. Enabling FPC allowed me to not be blocked from going to the checkout anymore. Before this I would login, add a product to cart but when I wanted to go to the checkout (through minicart) it would show the login popup as if I wasn't logged in. This doesn't happen anymore even after clearing cookies.

But I still have another problem which persists, and the change from the comment from @100php didn't change anything in that regard. After logging in I'm redirected to MyAccount page and I see my username in the header. However, as soon as I go to any product overview or details page my name disappears in the header, and if I now want to add a product to my wishlist I get that login popup again.
Does anyone have any ideas on how to solve that part?

Now I have all caches enabled, and the minicart items are always visible now from what I can tell, so that's progress compared to before.

@pantaoran is your full page cache on?

It's weird... Same problem as @pantaoran.
With all cache enabled, I'm using $this->session->getCustomerId() to know if the customer is logged in or not, then render the name in the top op header and enable other features.
$this->session is a Magento\Customer\Model\Session object.
After login I can see the customer's name on top, but it disappear in CMS pages, product overview page, product details page... Reappear in checkout.
I'm using the code suggested by @100php ...

@100php my last sentence specifically answered your question. I said "now I have all caches enabled".

@pantaoran Thank you for confirmation. As we see in the admin pf Magento 2.0.7 built-in caching is not recommended for Production Use(check the image below).

image

There are two parts to this issue ::

  1. Minicart - Minicart do not work when full page cache(FPC) is disabled. But it works perfectly fine when we enable FPC. The actual problem here is as described by @sky4git .
  2. Login/customer section - If we enable magento inbuilt FPC, there are session related issues. Its not only the cached HTML but we do not get customer session even after login when FPC is enabled. This is creating issue on cart and checkout pages too...

Temporary Solution :: Stop using Magento inbuilt FPC and use Varnish instead. And the above code given by me will allow us to resolve the minicart issue temporarily.

@pantaoran @sengaigibon For me, everything working fine after I enable FPC. I know its not recommended to use in Dev mode, but that is the solution for now.

For your mincart issue, I recommend to check any broken layout issue in related XML files in system log. Sometimes even if everything is right, it can make stop things working properly. This would be the case if your working on custom theme not on standard luma theme.

@100php Not sure, but in your temporary solution, should we need to add _customer_ section also?
var reloadsections = ['cart','messages', 'customer'];

@sky4git this is totally dependent on your environment and requirement. We needed on session messages and cart(minicart) you can add other sections also. This will load all these section on every action ex. pageload, add to cart, remove from cart etc...

Updating my status here...
I added var reloadsections = ['cart','messages', 'customer']; to my own copy of customer-data.js and so far, after I log in, it solves the number of products in the mini cart of my previous sessions and I can go directly to the checkout without prompting the popup authentication form.
As I read in #2010 , I made my header block cachable=false and it solves my problems with the name in the top bar and other issues with the name in other sections.

It's still weird that in product overview page and product detail page, the session file is empty for the object class Magento\Customer\Model\Session but not for \Magento\Framework\App\Http\Context

Anyway, so far I'm not experiencing this bug anymore... until further notice!

We will close this issue as not updated more than 2 weeks if this issue still reproducible please feel free to create the new one.

@sevos1984 I was able to work around the issue by modifying several core files. This is a hackish workaround which is not a real solution. If I remove those modifications then the issue is definitely still reproducible. I feel that the solution would need to come in form of a patch or a new release, and this issue should not be closed yet.

+1
M2.1.1

Magento Dev,
We need a resolution on this. I am running M2.1.1 (as on today, the latest that Magento offers).

I have the issue - After login, the name do not get set in the welcome string, the cart shows no items and we have no clue what is causing this. We are live on production and is causing us a lot of pain because of this. Please get this fixed and get me a workaround on this asap.

Appreciate your help.

@apurv-anand this ticket is closed. Per the last comment, can you open a new ticket that has full information in terms of version, system info, and steps so we can reproduce?

This issue is closed without anyone ack that issue is indeed resolved. Everyone is trying to have a workaround and somehow make things work. I have opened a new ticket anyway.
https://github.com/magento/magento2/issues/6759

@apurv-anand correct--closed has several possible resolutions. We can close an issue because it is resolved or close an issue because it is not an issue at all. One other common source is when we do not have enough info to reproduce a reported issue. When this happens we ask for updates to the ticket and IF we receive no updates to help reproduce we will close the issue. If you look above that is what happened here when the original reporter did not provide details needed so the issue report was closed.

For me @100php 's solution worked. Customer name was not loading for me in top menu. So I added these lines in my JS file:
var reloadsections = ['customer','cart','messages','directory-data']; this.reload(reloadsections,true);

and it started working :)

Was this page helpful?
0 / 5 - 0 ratings