jcfilho
10/11/2018 - 6:07 PM

Add error or success messages with javascript

Add error or success messages with javascript

define(
    [
        'jquery',
        'Magento_Customer/js/customer-data',
        'mage/translate'
    ],
    function($,$customerData){

      var showMessage = function(){
        var nameProduct = 'this is the message';
        var messageError = $.mage.__('%s has already started.').replace('%s', nameProduct);
        customerData.set('messages', {
            messages: [{
                type: 'error',
                text: messageError
            }]
        });   
      }
    }
);