I want to display messages on the cart page. I have made a custom module so that the shopping cart will automatically reload when the qty changes using AJAX.

Here is my js code:

], function ($, getTotalsAction, customerData) {

$(document).on('change', 'input[name$="[qty]"]', function(){
    var form = $('form#form-validate');
        url: form.attr('action'),
        data: form.serialize(),
        showLoader: true,
        success: function (res) {
            var parsedResponse = $.parseHTML(res);
            var result = $(parsedResponse).find("#form-validate");


            //reload minicart
            var sections = ['cart'];
            customerData.reload(sections, true);

            //reload total summary
            var deferred = $.Deferred();
            getTotalsAction([], deferred);

        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");


If I update qty in cart so that the qty is higher than the quantity available. I want to display a message like "The requested qty is not available"?

Can I use customerData to show error messages and display them on the page?


3 Answers 3


This is how Magento is doing it in the minicart. Maybe it helps you.



Finally was able to fix issue. I just had to reload the message after setting CustomerData message section.

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

            //reload messages section
            var messages_section = ['messages'];
  • can you please update the full code.... where you have added the code in asked question code. Mar 28, 2022 at 14:29

Go to Magento admin and edit any item. There is one link available below QTY field advanced inventory. Click on that option. There is one text field available for it.

Maximum Qty Allowed in Shopping Cart you can uncheck Use Config Settings and set QTY there.

Save that product.

Hope it will help you.

  • I think that's not really what I am looking for. I would like my website to show a custom message when a customer adds a quantity that exceeded the stock size. Sep 4, 2020 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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