Search code examples
cookiescomparelocal-storagemagento2magento2.2

Magento 2: Completely disable Recently Viewed & Compared // disable Cookie setting


In our Magento 2.2.2 installation we have removed all "Recently Viewed" and "Compared" elements from our site (removed via XML files in our custom theme). We do not need these functionalities at all and removing all elements worked fine so far. However:

The functionalitites itselves are obviously still enabled and create unnecessary output. Most important issue is that still COOKIES / HTML Local Storage are being set:

recently_viewed_product | recently_viewed_product_previous | recently_compared_product | recently_compared_product_previous

Is there a way to COMPLETELY disable these features so that there will be not output at all / no cookies will be set any longer? Or another way to just stop Magento to set these cookies?

Thanks for your help! Alex


Solution

  • We also had that issue and decided to develop two open source modules to fix this:

    Technically, both modules add a mixin for Magento_Catalog/js/storage-manager. In the mixin, we extend the function prepareStoragesConfig and remove the respective configuration from the storagesConfiguration:

    define([], function () {
        'use strict';
    
        return function (storageManager) {
            return storageManager.extend({
                prepareStoragesConfig: function () {
                    if (typeof this.storagesConfiguration === 'object') {
                        delete this.storagesConfiguration.recently_compared_product;
                    }
                    return this._super();
                }
            });
        };
    });
    

    One thing to watch out for is that there is still the cookie product_data_storage. I am not totally sure if this is only used for the product comparison / viewed products feature and can therefore also be removed or if this needs to be kept... I tend to ignore this issue for the time being and claim that product_data_storage is a technically necessary cookie ;-)