0

My code :

define([
    'Magento_Customer/js/model/authentication-popup',
    'Magento_Ui/js/modal/alert',
    'Magento_Ui/js/modal/confirm',
    'underscore',
    'jquery/ui',
    'jquery-ui-modules/core',
    'jquery-ui-modules/widget',
    'mage/decorate',
    'mage/collapsible',
    'mage/cookies',
    'loader'
], function ($, authenticationPopup, customerData, alert, confirm, _) {
    'use strict';
   
    return function (widget) {

        $.widget('mage.sidebar', widget, {

            _updateItemQty: function (elem) {
                
                var itemId = elem.data('cart-item');

                var btnplus = elem.data('btn-plus');
                var btnminus = elem.data('btn-minus');

                $('#cart-item-' + itemId + '-qty').trigger('processStart');
                this._ajax(this.options.url.update, {
                    'item_id': itemId,
                    'item_qty': $('#cart-item-' + itemId + '-qty').val(),
                    'item_btn_plus': btnplus,
                    'item_btn_minus': btnminus,
                   
                }, elem, this._updateItemQtyAfter);
                $('#cart-item-' + itemId + '-qty').trigger('processStop');
               
                this._customerData();

            },

            /**
             * Update content after update qty
             *
             * @param {HTMLElement} elem
             */
            _updateItemQtyAfter: function (elem) {
                var productData = this._getProductById(Number(elem.data('cart-item')));

                if (!_.isUndefined(productData)) {
                    $(document).trigger('ajax:updateCartItemQty');

                    if (window.location.href === this.shoppingCartUrl) {
                        window.location.reload(false);
                    }
                }
                this._hideItemButton(elem);
            },

            _customerData : function ()  {
                var sections = ['cart'];
                customerData.invalidate(sections);
                customerData.reload(sections, true);
            }
        }
        ); 
        return $.mage.sidebar; 
    }
});

Console Error 1 : https://snipboard.io/4NK3b5.jpg

Console Error 2 : https://snipboard.io/iqX8yF.jpg

Module : https://github.com/kirtinariya1/MinicartAjaxQtyIncrementDecrement

3
  • you need to add 'jquery', in define!
    – Pawan
    Apr 8, 2021 at 8:05
  • Now i am getting snipboard.io/4lvOEy.jpg
    – zus
    Apr 8, 2021 at 8:15
  • you need to put condition like: if (sections) { YOUR CODE }
    – Pawan
    Apr 8, 2021 at 8:20

2 Answers 2

0

Try:-

define([
    'jquery',
    'Magento_Customer/js/model/authentication-popup',
    'Magento_Customer/js/customer-data',
    'Magento_Ui/js/modal/alert',
    'Magento_Ui/js/modal/confirm',
    'underscore',
    'jquery/ui',
    'jquery-ui-modules/core',
    'jquery-ui-modules/widget',
    'mage/decorate',
    'mage/collapsible',
    'mage/cookies',
    'loader'
], function ($, authenticationPopup, customerData, alert, confirm, _) {
    'use strict';
   
    return function (originalWidget) {

        $.widget('mage.sidebar', widget, {

            _updateItemQty: function (elem) {
                
                var itemId = elem.data('cart-item');

                var btnplus = elem.data('btn-plus');
                var btnminus = elem.data('btn-minus');

                $('#cart-item-' + itemId + '-qty').trigger('processStart');
                this._ajax(this.options.url.update, {
                    'item_id': itemId,
                    'item_qty': $('#cart-item-' + itemId + '-qty').val(),
                    'item_btn_plus': btnplus,
                    'item_btn_minus': btnminus,
                   
                }, elem, this._updateItemQtyAfter);
                $('#cart-item-' + itemId + '-qty').trigger('processStop');
               
                this._customerData();

            },

            /**
             * Update content after update qty
             *
             * @param {HTMLElement} elem
             */
            _updateItemQtyAfter: function (elem) {
                var productData = this._getProductById(Number(elem.data('cart-item')));

                if (!_.isUndefined(productData)) {
                    $(document).trigger('ajax:updateCartItemQty');

                    if (window.location.href === this.shoppingCartUrl) {
                        window.location.reload(false);
                    }
                }
                this._hideItemButton(elem);
            },

            _customerData : function ()  {
                var sections = ['cart'];
                customerData.invalidate(sections);
                customerData.reload(sections, true);
            }
        }
        ); 
        return $.mage.sidebar; 
    }
});
0

I installed your module and found that it is working fine, without any errors given in the console tab (you can see the video that I recorded) https://www.loom.com/share/fa457f25e46f471ba493b6fd8a09846c

Your Answer

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

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