2

Magento2

Notification is showing again and again even after page refresh while should show only one time and should hide on page refresh.

Please anybody can help to fix this.

enter image description here

1

Hello Vijay

Put this code on message.js

 return Component.extend({
defaults: {
    cookieMessages: [],
    messages: []
},

/** @inheritdoc */
initialize: function () {
    this._super();

    $('#validation-login-cust').html('');
    $('#valid-promo-cart').html('');
    try {
        var message = _.unique($.cookieStorage.get('mage-messages'), 'text');
        var textMessage =  JSON.parse(message[0]["text"]);
        if (textMessage['type'] === "inline"){
            $(textMessage["selector"]).text(textMessage["message"]).css('color', 'red');
        }

        this.messages = customerData.get('messages').extend({
            disposableCustomerData: 'messages'
        });

        if (!_.isEmpty(this.messages().messages)) {
            customerData.set('messages', {});
        }

        customerData.set('messages', {messages: ""});
        $.cookieStorage.set('mage-messages', '');

    }catch (e) {

        $('#validation-login-cust').html('');
        $('#valid-promo-cart').html('');
        var messageText = _.unique($.cookieStorage.get('mage-messages'), 'text')[_.unique($.cookieStorage.get('mage-messages'), 'text').length-1];
        if (messageText) {
            if (messageText["text"].trim() == "Invalid Form Key. Please refresh the page.") {
                this.cookieMessages = 'OOps! Something went wrong, Please try again later or refresh the page.';
            } else {
                this.cookieMessages = messageText;
            }
        }
        this.messages = customerData.get('messages').extend({
            disposableCustomerData: 'messages'
        });
        if (!_.isEmpty(this.messages().messages)) {
            customerData.set('messages', {});
        }
    }
    var setCookieInterval = setInterval(function()
    {
        $.cookieStorage.set('mage-messages', '');
        YX_UI_UTIL.eraseCookie("mage-messages");

    }, 3000);
    setTimeout(function( ) { clearInterval(setCookieInterval); }, 10000);
}

});

Please use this code, your issue will be resolved:)

If you find this usefull please vote and accept the Answer

Thanks

4
  • Hi Munesh, Please explain where should i write this script? – vijay gupta Jan 14 at 13:04
  • you can put this code on message.js – Munesh Jalwani Jan 14 at 13:07
  • It works, thank you – vijay gupta Jan 14 at 13:23
  • You are Welcome – Munesh Jalwani Jan 14 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.