Skip to content

messages.js breaks minicart item count update in mixed HTTP/HTTPS mode #6487

Closed
@torbre16

Description

@torbre16

Preconditions

  1. Magento 2.1.0 (also all release candidates), Magento 2.1.1

Steps to reproduce

  1. Use Magento in mixed HTTP/HTTPS mode (i. e. unsecure base URL uses HTTP, secure base URL uses HTTPS)
  2. Add a product to the cart on a product details page
  3. Go to the cart page and change the quantity of the previously added product
  4. Go back to the product details page (reload it). Sporadically, the number of items in the minicart is not updated correctly.

Expected result

  1. Show the correct number of items in the minicart both on HTTPS and HTTP pages.

Actual result

  1. 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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions