3

My error/success messages in Magento has latency, means it appears when I go to the next page. i.e, When I add a product to cart, instead of showing a success notification message on the refresh of the page, it shows nothing and it appears when I browse to any other page next, then I see Your product has been added to cart message. Sometimes this happens all over the page and sometimes not. Random behavior

How to fix that, and move the notification message to the top instead of the bottom for all pages?

Something like this below header. It should for all pages, so instead of writing to <move> container in respective XML, I want to move it at the top for all pages.

enter image description here

  • did it happen when you use the default Magento theme? – fmsthird Mar 11 at 3:41
  • @magefms I am using Amely theme – summu Mar 11 at 4:01
1

On your ajax add to cart success function you need to add following lines

//Display error if found after jquery
var messages = $.cookieStorage.get('mage-messages');
if (!_.isEmpty(messages)) {
    customerData.set('messages', {messages: messages});
    $.cookieStorage.set('mage-messages', '');
}

I was facing almost same issue and fixed by this small script

And to move notification messages top of the page, please follow this link, this will help you move messages anywhere in your code

Magento 2: Change message location

  • @Shoaid Munir How can I move it to top for all pages, like global – summu Mar 11 at 5:47
  • No need to move top of all pages, you need to add it in your ajax add to cart success function – Shoaib Munir Mar 11 at 5:51
  • @Shoaid Munir, My UI requirement is to move it to top of the pages, as I added the image also. Moving notification at the top is one part of the issue and latency part was another part. So i am asking moving notifications at the top of the pages – summu Mar 11 at 5:57
  • I have updated my answer, please check now – Shoaib Munir Mar 11 at 6:03
  • How can i remove the multiple notifications which appear in stack form one upon another, i want to remove the previous one and replace the current one – summu Mar 11 at 7:31

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.