0

I am trying to use:

Magento_Ui/js/model/messageList

messageList.addSuccessMessage({ message: 'You have subscribed Successfully' });

But its not working . I tried adding success message in the controller but its not showing up as well .

define([
        'jquery',
        'Magento_Ui/js/modal/modal',
        'Magento_Ui/js/model/messageList',
        'mage/cookies',

        ], function ($, modal,messageList) {
        'use strict';
        debugger;
         if(!$.cookie('popup_cookie') ) {
             $.widget('devall.popupManager', {

                /**
                 *
                 * @private
                 */

                _create: function () {

                    var self = this,
                        popup_devnewsletter_options = {
                            type: 'popup',
                            responsive: true,
                            innerScroll: true,
                            title: this.options.popupTitle,
                            buttons: false,
                            modalClass: 'popup-devnewsletter'
                        };
                    var expDate = new Date();

                    expDate.setTime(expDate.getTime() + (3650000 * 60 * 1000));
                    $.cookie('popup_cookie', 1, {expires: expDate});

                    modal(popup_devnewsletter_options, this.element);
                    setTimeout(function () {
                        self._setStyleCss();
                        self.element.modal('openModal');
                    }, 3000);
                    this.element.find('form').submit(function () {
                        if ($(this).validation('isValid')) {
                            console.log("Hello 1!");
                            $.ajax({
                                url: $(this).attr('action'),
                                cache: true,
                                data: $(this).serialize(),
                                dataType: 'json',
                                type: 'POST',
                                showLoader: true,
                            }).done(function (data) {
                                console.log("Hello 2!");
                                self.element.find('.popup-manager .messages').html(data.message);
                                if (data.error) {
                                    self.element.find('.messages .message').addClass('message-error error');
                                    self.element.find('.messages .message').addClass('message-success success');
                                    messageList.addSuccessMessage({ message: 'You have subscribed Successfully' });
                                    self.element.modal('closeModal');
                                    // var cookieExpires = new Date(new Date().getTime() + this.options.cookieLifetime * 1000);

                                    setTimeout(function () {
                                        self.element.modal('closeModal');
                                    }, 1000);
                                }
                                self.element.find('.messages').show();
                                setTimeout(function () {
                                    self.element.find('.messages').hide();
                                }, 5000);
                            }) 

                        }
                        return false;
                    });


                    this._resetStyleCss();
                },

                /**
                 * Set width of the popup
                 * @private
                 */
                _setStyleCss: function (width) {

                    width = width || 400;

                    if (window.innerWidth > 786) {
                        this.element.parent().parent('.modal-inner-wrap').css({'max-width': width + 'px'});
                    }
                },

                /**
                 * Reset width of the popup
                 * @private
                 */
                _resetStyleCss: function () {
                    var self = this;
                    $(window).resize(function () {
                        if (window.innerWidth <= 786) {
                            self.element.parent().parent('.modal-inner-wrap').css({'max-width': 'initial'});
                        } else {
                            self._setStyleCss(self.options.innerWidth);
                        }
                    });
                },

            });

            return $.devall.popupManager;
        }

        return 0; 
});
0

Use customer-data to display message.

Magento_Customer/js/customer-data,

customerData.set('messages', {
    messages: [{
        type: 'success',
        text: 'Your message'
    }]
});
| improve this answer | |

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.