With Magento 2.0.4 cache, more specifically page cache enabled, everything works.
If I disable it, clear cookies, and login as customer than products in minicart are not there.
Welcome message does not really work right.
I have to add a product to cart from a product page in order to see the minicart. Than if I go to checkout, country is not displayed in address summary (shipping address already added in my account).
I've done debugging and it looks like the problem is pointing to:
module-customer/view/frontend/web/js/customer-data.js
.
The cookie private_content_version
is set in module-page-cache/view/frontend/web/js/page-cache.js
and used in customer-data.js
. See customerData::reload
function.
With page cache disabled, the data is not loaded from the server as the function dataProvider::getFromServer()
does.
When page cache is disabled the cookie private_content_version
is not there (page-cache.js is not executed off course). But the cookie section_data_ids
has only '*' and 'messages' => empty (false or null).
When page cache is enabled there is private_content_version
and section_data_ids
has what keys with values:
*: null
cart: 123
compare-products: 123
customer: 123
directory-data: 123
last-ordered-items: 123
multiplewishlist: 123
review: 123
wishlist: 123
After I login with page cache enabled, on customer dashboard there are 2 additional ajax requests that load data:
http://test.localhost/customer/section/load/?sections=&update_section_id=false&_=123
http://test.localhost/customer/section/load/?sections=directory-data&update_section_id=false&_=123
These contain json objects with customer specific data and directory data like all countries and regions.
With these calls, on checkout the address summary displays the country name.
See: module-customer/view/frontend/web/js/sections-config.js
and module-checkout/view/frontend/web/js/view/shipping-address/address-renderer/default.js
, function getCountryName
.
Is this a Magento 2 bug or it's something that I messed up ?
Thanks
Best Answer
This does appear to be an outstanding issue, though perhaps it is resolved in newer versions of M2. See Magento GitHub issues:
"No items" in minicart in 2.1 (open as of this writing)
Minicart empty if FPC disabled in Magento 2.1.1 (open as of this writing)
Minicart shows no product even when I have products in cart (closed)
As far as what you can try...
If this is cookie-related, you may be able to rule out some possibilities by visiting your site in a private browsing/incognito browser. Go through your workflow (not logged in, add product to cart, customer log in, look at /checkout/cart and minicart dropdown).
Additionally, it may be helpful to review the M2 dev docs for best practices regarding configuration of the caches in development versus configuration in production. In my experience, in development, it is OK to have all caches enabled in development, and simply flush when required (read docs for descriptions of each cache). Note, as a mostly front-end dev, I personally prefer to develop with FPC, Blocks output, and layout caches disabled - this allows frontend changes to be seen more easily.