Description
Preconditions
- Magento 2.1.0 (also all release candidates), Magento 2.1.1
Steps to reproduce
- Use Magento in mixed HTTP/HTTPS mode (i. e. unsecure base URL uses HTTP, secure base URL uses HTTPS)
- Add a product to the cart on a product details page
- Go to the cart page and change the quantity of the previously added product
- Go back to the product details page (reload it). Sporadically, the number of items in the minicart is not updated correctly.
Expected result
- Show the correct number of items in the minicart both on HTTPS and HTTP pages.
Actual result
- Sporadically, the number of items in the minicart is not updated correctly when switching between HTTP and HTTPS pages.
Root cause
The number of items in the minicart is stored in the browser's local storage. As the browser has different local storages for HTTP and HTTPS pages, Magento uses a 'section_data_ids' cookie to remember what local storage keys to invalidate (this is all performed in module-customer/view/frontend/web/js/customer-data.js
).
The file module-theme/view/frontend/web/js/view/messages.js
sets the expires
parameter of the cookie storage globally to -1
in the initialize
method. Effectively, this disables the cookie storage feature completely in case a new cookie is set via $.cookieStorage
, and thus also breaks $.cookieStorage.set('section_data_ids', [...]);
which is used to update the number of items in the minicart.
In our case, it helped to change the line
$.cookieStorage.setConf({path: '/', expires: -1}).set('mage-messages', null);
in module-theme/view/frontend/web/js/view/messages.js
to
$.cookieStorage.setConf({path: '/'}).set('mage-messages', null);
to fix the issue, but I am not completely sure if this breaks something else in regards to the error message handling (not sure why the expires
parameter has been set to -1
originally).