{"id":102,"date":"2021-07-13T00:11:57","date_gmt":"2021-07-13T00:11:57","guid":{"rendered":"https:\/\/bslthemes.site\/vcard\/?p=102"},"modified":"2022-12-13T07:54:39","modified_gmt":"2022-12-13T07:54:39","slug":"plus-minus-automatic-cart-update-on-magento-2","status":"publish","type":"post","link":"https:\/\/atish.co.in\/?p=102","title":{"rendered":"Plus, Minus, automatic cart update on Magento 2"},"content":{"rendered":"<p>vendor\\magento\\module-checkout\\view\\frontend\\web\\template\\minicart\\item\\default.html<\/p>\n<p>Copy to default.html<\/p>\n<p>app\\design\\yourvendor\\yourtheme\\Magento_Checkout\\web\\template\\minicart\\item\\default.html<\/p>\n<p>add + and &#8211; button as span tag in line number 74 and 84.<\/p>\n<p>Or insert red line code<br \/>\n[code language=&#8221;html&#8221;]<br \/>\n&lt;!&#8211;<br \/>\n\/**<br \/>\n * Copyright \u00a9 Magento, Inc. All rights reserved.<br \/>\n * See COPYING.txt for license details.<br \/>\n *\/<br \/>\n&#8211;&gt;<br \/>\n&lt;li class=&quot;item product product-item&quot; data-role=&quot;product-item&quot;&gt;<br \/>\n    &lt;div class=&quot;product&quot;&gt;<br \/>\n        &lt;div class=&quot;product-item-photo&quot;&gt;<br \/>\n            &lt;!&#8211; ko if: product_has_url &#8211;&gt;<br \/>\n            &lt;a data-bind=&quot;attr: {href: product_url, title: product_name}&quot; tabindex=&quot;-1&quot; class=&quot;product-item-photo&quot;&gt;<br \/>\n                &lt;!&#8211; ko foreach: $parent.getRegion(&#8216;itemImage&#8217;) &#8211;&gt;<br \/>\n                    &lt;!&#8211; ko template: {name: getTemplate(), data: item.product_image} &#8211;&gt;&lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n            &lt;\/a&gt;<br \/>\n            &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n            &lt;!&#8211; ko ifnot: product_has_url &#8211;&gt;<br \/>\n            &lt;span class=&quot;product-item-photo&quot;&gt;<br \/>\n                &lt;!&#8211; ko foreach: $parent.getRegion(&#8216;itemImage&#8217;) &#8211;&gt;<br \/>\n                    &lt;!&#8211; ko template: {name: getTemplate(), data: item.product_image} &#8211;&gt;&lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n            &lt;\/span&gt;<br \/>\n            &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n            &lt;div class=&quot;product actions&quot;&gt;<br \/>\n                &lt;!&#8211; ko if: is_visible_in_site_visibility &#8211;&gt;<br \/>\n                &lt;div class=&quot;primary&quot;&gt;<br \/>\n                    &lt;a data-bind=&quot;attr: {href: configure_url, title: $t(&#8216;Edit item&#8217;)}&quot; class=&quot;action edit&quot;&gt;<br \/>\n                        &lt;span data-bind=&quot;i18n: &#8216;Edit&#8217;&quot;&gt;&lt;\/span&gt;<br \/>\n                    &lt;\/a&gt;<br \/>\n                &lt;\/div&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;div class=&quot;secondary&quot;&gt;<br \/>\n                    &lt;a href=&quot;#&quot; data-bind=&quot;attr: {&#8216;data-cart-item&#8217;: item_id, title: $t(&#8216;Remove item&#8217;)}&quot;<br \/>\n                       class=&quot;action delete&quot;&gt;<br \/>\n                        &lt;span data-bind=&quot;i18n: &#8216;Remove&#8217;&quot;&gt;&lt;\/span&gt;<br \/>\n                    &lt;\/a&gt;<br \/>\n                &lt;\/div&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        &lt;\/div&gt;<br \/>\n        &lt;div class=&quot;product-item-details&quot;&gt;<br \/>\n            &lt;strong class=&quot;product-item-name&quot;&gt;<br \/>\n                &lt;!&#8211; ko if: product_has_url &#8211;&gt;<br \/>\n                &lt;a data-bind=&quot;attr: {href: product_url}, html: product_name&quot;&gt;&lt;\/a&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;!&#8211; ko ifnot: product_has_url &#8211;&gt;<br \/>\n                    &lt;!&#8211; ko text: product_name &#8211;&gt;&lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n            &lt;\/strong&gt;<\/p>\n<p>            &lt;!&#8211; ko if: options.length &#8211;&gt;<br \/>\n            &lt;div class=&quot;product options&quot; data-mage-init='{&quot;collapsible&quot;:{&quot;openedState&quot;: &quot;active&quot;, &quot;saveState&quot;: false}}&#8217;&gt;<br \/>\n                &lt;span data-role=&quot;title&quot; class=&quot;toggle&quot;&gt;&lt;!&#8211; ko i18n: &#8216;See Details&#8217; &#8211;&gt;&lt;!&#8211; \/ko &#8211;&gt;&lt;\/span&gt;<\/p>\n<p>                &lt;div data-role=&quot;content&quot; class=&quot;content&quot;&gt;<br \/>\n                    &lt;strong class=&quot;subtitle&quot;&gt;&lt;!&#8211; ko i18n: &#8216;Options Details&#8217; &#8211;&gt;&lt;!&#8211; \/ko &#8211;&gt;&lt;\/strong&gt;<br \/>\n                    &lt;dl class=&quot;product options list&quot;&gt;<br \/>\n                        &lt;!&#8211; ko foreach: { data: options, as: &#8216;option&#8217; } &#8211;&gt;<br \/>\n                        &lt;dt class=&quot;label&quot;&gt;&lt;!&#8211; ko text: option.label &#8211;&gt;&lt;!&#8211; \/ko &#8211;&gt;&lt;\/dt&gt;<br \/>\n                        &lt;dd class=&quot;values&quot;&gt;<br \/>\n                            &lt;!&#8211; ko if: Array.isArray(option.value) &#8211;&gt;<br \/>\n                                &lt;span data-bind=&quot;html: option.value.join(&#8216;&lt;br&gt;&#8217;)&quot;&gt;&lt;\/span&gt;<br \/>\n                            &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                            &lt;!&#8211; ko if: (!Array.isArray(option.value) &amp;&amp; [&#8216;file&#8217;, &#8216;html&#8217;].includes(option.option_type)) &#8211;&gt;<br \/>\n                                &lt;span data-bind=&quot;html: option.value&quot;&gt;&lt;\/span&gt;<br \/>\n                            &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                            &lt;!&#8211; ko if: (!Array.isArray(option.value) &amp;&amp; ![&#8216;file&#8217;, &#8216;html&#8217;].includes(option.option_type)) &#8211;&gt;<br \/>\n                            &lt;span data-bind=&quot;text: option.value&quot;&gt;&lt;\/span&gt;<br \/>\n                            &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                        &lt;\/dd&gt;<br \/>\n                        &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                    &lt;\/dl&gt;<br \/>\n                &lt;\/div&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n            &lt;!&#8211; \/ko &#8211;&gt;<\/p>\n<p>            &lt;div class=&quot;product-item-pricing&quot;&gt;<br \/>\n                &lt;!&#8211; ko if: canApplyMsrp &#8211;&gt;<\/p>\n<p>                &lt;div class=&quot;details-map&quot;&gt;<br \/>\n                    &lt;span class=&quot;label&quot; data-bind=&quot;i18n: &#8216;Price&#8217;&quot;&gt;&lt;\/span&gt;<br \/>\n                    &lt;span class=&quot;value&quot; data-bind=&quot;i18n: &#8216;See price before order confirmation.&#8217;&quot;&gt;&lt;\/span&gt;<br \/>\n                &lt;\/div&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;!&#8211; ko ifnot: canApplyMsrp &#8211;&gt;<br \/>\n                &lt;!&#8211; ko foreach: $parent.getRegion(&#8216;priceSidebar&#8217;) &#8211;&gt;<br \/>\n                    &lt;!&#8211; ko template: {name: getTemplate(), data: item.product_price, as: &#8216;price&#8217;} &#8211;&gt;&lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<br \/>\n                &lt;!&#8211; \/ko &#8211;&gt;<\/p>\n<p>                &lt;div class=&quot;details-qty qty&quot;&gt;<br \/>\n                    &lt;label class=&quot;label&quot; data-bind=&quot;i18n: &#8216;Qty&#8217;, attr: {<br \/>\n                           for: &#8216;cart-item-&#8216;+item_id+&#8217;-qty&#8217;}&quot;&gt;&lt;\/label&gt;<br \/>\n                           &lt;span data-bind=&quot;attr: { id: item_id }&quot; class=&quot;minus&quot; &gt;-&lt;\/span&gt;<br \/>\n                    &lt;input data-bind=&quot;attr: {<br \/>\n                           id: &#8216;cart-item-&#8216;+item_id+&#8217;-qty&#8217;,<br \/>\n                           &#8216;data-cart-item&#8217;: item_id,<br \/>\n                           &#8216;data-item-qty&#8217;: qty,<br \/>\n                           &#8216;data-cart-item-id&#8217;: product_sku<br \/>\n                           }, value: qty&quot;<br \/>\n                           type=&quot;number&quot;<br \/>\n                           size=&quot;4&quot;<br \/>\n                           class=&quot;item-qty cart-item-qty&quot;&gt;<br \/>\n                           &lt;span data-bind=&quot;attr: { id: item_id }&quot; class=&quot;plus&quot; &gt;+&lt;\/span&gt;<br \/>\n                    &lt;button data-bind=&quot;attr: {<br \/>\n                           id: &#8216;update-cart-item-&#8216;+item_id,<br \/>\n                           &#8216;data-cart-item&#8217;: item_id,<br \/>\n                           title: $t(&#8216;Update&#8217;)<br \/>\n                           }&quot;<br \/>\n                            class=&quot;update-cart-item&quot;<br \/>\n                            style=&quot;display: none&quot;&gt;<br \/>\n                        &lt;span data-bind=&quot;i18n: &#8216;Update&#8217;&quot;&gt;&lt;\/span&gt;<br \/>\n                    &lt;\/button&gt;<br \/>\n                &lt;\/div&gt;<br \/>\n            &lt;\/div&gt;<br \/>\n        &lt;\/div&gt;<br \/>\n    &lt;\/div&gt;<br \/>\n    &lt;div class=&quot;message notice&quot; if=&quot;$data.message&quot;&gt;<br \/>\n        &lt;div data-bind=&quot;text: $data.message&quot;&gt;&lt;\/div&gt;<br \/>\n    &lt;\/div&gt;<br \/>\n&lt;\/li&gt;<\/p>\n<p>[\/code]<\/p>\n<p>override\u00a0<code>sidebar.js<\/code>\u00a0from<\/p>\n<blockquote><p>vendor\\magento\\module-checkout\\view\\frontend\\web\\js\\sidebar.js<\/p><\/blockquote>\n<p>to<\/p>\n<blockquote><p>app\\design\\yourvendor\\yourtheme\\Magento_Checkout\\web\\js\\sidebar.js<\/p><\/blockquote>\n<p>[code language=&#8221;javascript&#8221;]<\/p>\n<p>\/**<br \/>\n * Copyright \u00a9 Magento, Inc. All rights reserved.<br \/>\n * See COPYING.txt for license details.<br \/>\n *\/<\/p>\n<p>define([ &#8216;jquery&#8217;, &#8216;Magento_Customer\/js\/model\/authentication-popup&#8217;, &#8216;Magento_Customer\/js\/customer-data&#8217;, &#8216;Magento_Ui\/js\/modal\/alert&#8217;, &#8216;Magento_Ui\/js\/modal\/confirm&#8217;, &#8216;underscore&#8217;, &#8216;jquery\/ui&#8217;, &#8216;mage\/decorate&#8217;, &#8216;mage\/collapsible&#8217;, &#8216;mage\/cookies&#8217; ], function ($, authenticationPopup, customerData, alert, confirm, _) { &#8216;use strict&#8217;;<\/p>\n<p>    $.widget(&#8216;mage.sidebar&#8217;, {<br \/>\n    options: {<br \/>\n        isRecursive: true,<br \/>\n        minicart: {<br \/>\n            maxItemsVisible: 3<br \/>\n        }<br \/>\n    },<br \/>\n    scrollHeight: 0,<br \/>\n    shoppingCartUrl: window.checkout.shoppingCartUrl,<\/p>\n<p>    \/**<br \/>\n     * Create sidebar.<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _create: function () {<br \/>\n        this._initContent();<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * Update sidebar block.<br \/>\n     *\/<br \/>\n    update: function () {<br \/>\n        $(this.options.targetElement).trigger(&#8216;contentUpdated&#8217;);<br \/>\n        this._calcHeight();<br \/>\n        this._isOverflowed();<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _initContent: function () {<br \/>\n        var self = this,<br \/>\n            events = {};<\/p>\n<p>        this.element.decorate(&#8216;list&#8217;, this.options.isRecursive);<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;click &#8216; + this.options.button.close] = function (event) {<br \/>\n            event.stopPropagation();<br \/>\n            $(self.options.targetElement).dropdownDialog(&#8216;close&#8217;);<br \/>\n        };<br \/>\n        events[&#8216;click &#8216; + this.options.button.checkout] = $.proxy(function () {<br \/>\n            var cart = customerData.get(&#8216;cart&#8217;),<br \/>\n                customer = customerData.get(&#8216;customer&#8217;),<br \/>\n                element = $(this.options.button.checkout);<\/p>\n<p>            if (!customer().firstname &amp;&amp; cart().isGuestCheckoutAllowed === false) {<br \/>\n                \/\/ set URL for redirect on successful login\/registration. It&#8217;s postprocessed on backend.<br \/>\n                $.cookie(&#8216;login_redirect&#8217;, this.options.url.checkout);<\/p>\n<p>                if (this.options.url.isRedirectRequired) {<br \/>\n                    element.prop(&#8216;disabled&#8217;, true);<br \/>\n                    location.href = this.options.url.loginUrl;<br \/>\n                } else {<br \/>\n                    authenticationPopup.showModal();<br \/>\n                }<\/p>\n<p>                return false;<br \/>\n            }<br \/>\n            element.prop(&#8216;disabled&#8217;, true);<br \/>\n            location.href = this.options.url.checkout;<br \/>\n        }, this);<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;click &#8216; + this.options.button.remove] =  function (event) {<br \/>\n            event.stopPropagation();<br \/>\n            confirm({<br \/>\n                content: self.options.confirmMessage,<br \/>\n                actions: {<br \/>\n                    \/** @inheritdoc *\/<br \/>\n                    confirm: function () {<br \/>\n                        self._removeItem($(event.currentTarget));<br \/>\n                    },<\/p>\n<p>                    \/** @inheritdoc *\/<br \/>\n                    always: function (e) {<br \/>\n                        e.stopImmediatePropagation();<br \/>\n                    }<br \/>\n                }<br \/>\n            });<br \/>\n        };<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;click &#8216; + &#8216;.minicart-items-wrapper .plus&#8217;] = function (event) {\/\/Custom event<br \/>\n            var plusId=event.target.id;<br \/>\n            var qtyBoxId=&#8217;#cart-item-&#8216;+plusId+&#8217;-qty&#8217;;<br \/>\n            var qtyVal = parseInt($(event.target).parent().find(this.options.item.qty).val());<br \/>\n            $(qtyBoxId).val(qtyVal + 1);<br \/>\n            event.stopPropagation();<br \/>\n            self._updateItemQty($(event.target).parent().find(this.options.item.button));<br \/>\n        };<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;click &#8216; + &#8216;.minicart-items-wrapper .minus&#8217;] = function (event) {\/\/Custom event<br \/>\n            var minusId=event.target.id;<br \/>\n            var qtyBoxId=&#8217;#cart-item-&#8216;+minusId+&#8217;-qty&#8217;;<br \/>\n            var qtyVal = parseInt($(event.target).parent().find(this.options.item.qty).val());<br \/>\n            if(qtyVal &gt; 1){<br \/>\n                $(qtyBoxId).val(qtyVal &#8211; 1);<br \/>\n                event.stopPropagation();<br \/>\n                self._updateItemQty($(event.target).parent().find(this.options.item.button));<br \/>\n            }<br \/>\n        };<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;keyup &#8216; + this.options.item.qty] = function (event) {\/\/Hide event for not displaying update button<br \/>\n            \/\/self._showItemButton($(event.target));<br \/>\n        };<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;change &#8216; + this.options.item.qty] = function (event) {\/\/Hide event for not displaying update button<br \/>\n            \/\/self._showItemButton($(event.target));<br \/>\n        };<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;click &#8216; + this.options.item.button] = function (event) {<br \/>\n            event.stopPropagation();<br \/>\n            self._updateItemQty($(event.currentTarget));<br \/>\n        };<\/p>\n<p>        \/**<br \/>\n         * @param {jQuery.Event} event<br \/>\n         *\/<br \/>\n        events[&#8216;focusout &#8216; + this.options.item.qty] = function (event) {<br \/>\n            self._validateQty($(event.currentTarget));<br \/>\n        };<\/p>\n<p>        this._on(this.element, events);<br \/>\n        this._calcHeight();<br \/>\n        this._isOverflowed();<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * Add &#8216;overflowed&#8217; class to minicart items wrapper element<br \/>\n     *<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _isOverflowed: function () {<br \/>\n        var list = $(this.options.minicart.list),<br \/>\n            cssOverflowClass = &#8216;overflowed&#8217;;<\/p>\n<p>        if (this.scrollHeight &gt; list.innerHeight()) {<br \/>\n            list.parent().addClass(cssOverflowClass);<br \/>\n        } else {<br \/>\n            list.parent().removeClass(cssOverflowClass);<br \/>\n        }<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @param {HTMLElement} elem<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _showItemButton: function (elem) {<br \/>\n        var itemId = elem.data(&#8216;cart-item&#8217;),<br \/>\n            itemQty = elem.data(&#8216;item-qty&#8217;);<\/p>\n<p>        if (this._isValidQty(itemQty, elem.val())) {<br \/>\n            $(&#8216;#update-cart-item-&#8216; + itemId).show(&#8216;fade&#8217;, 300);<br \/>\n        } else if (elem.val() == 0) { \/\/eslint-disable-line eqeqeq<br \/>\n            this._hideItemButton(elem);<br \/>\n        } else {<br \/>\n            this._hideItemButton(elem);<br \/>\n        }<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @param {*} origin &#8211; origin qty. &#8216;data-item-qty&#8217; attribute.<br \/>\n     * @param {*} changed &#8211; new qty.<br \/>\n     * @returns {Boolean}<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _isValidQty: function (origin, changed) {<br \/>\n        return origin != changed &amp;&amp; \/\/eslint-disable-line eqeqeq<br \/>\n            changed.length &gt; 0 &amp;&amp;<br \/>\n            changed &#8211; 0 == changed &amp;&amp; \/\/eslint-disable-line eqeqeq<br \/>\n            changed &#8211; 0 &gt; 0;<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @param {Object} elem<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _validateQty: function (elem) {<br \/>\n        var itemQty = elem.data(&#8216;item-qty&#8217;);<\/p>\n<p>        if (!this._isValidQty(itemQty, elem.val())) {<br \/>\n            elem.val(itemQty);<br \/>\n        }<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @param {HTMLElement} elem<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _hideItemButton: function (elem) {<br \/>\n        var itemId = elem.data(&#8216;cart-item&#8217;);<\/p>\n<p>        $(&#8216;#update-cart-item-&#8216; + itemId).hide(&#8216;fade&#8217;, 300);<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @param {HTMLElement} elem<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _updateItemQty: function (elem) {<br \/>\n        var itemId = elem.data(&#8216;cart-item&#8217;);<\/p>\n<p>        this._ajax(this.options.url.update, {<br \/>\n            &#8216;item_id&#8217;: itemId,<br \/>\n            &#8216;item_qty&#8217;: $(&#8216;#cart-item-&#8216; + itemId + &#8216;-qty&#8217;).val()<br \/>\n        }, elem, this._updateItemQtyAfter);<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * Update content after update qty<br \/>\n     *<br \/>\n     * @param {HTMLElement} elem<br \/>\n     *\/<br \/>\n    _updateItemQtyAfter: function (elem) {<br \/>\n        var productData = this._getProductById(Number(elem.data(&#8216;cart-item&#8217;)));<\/p>\n<p>        if (!_.isUndefined(productData)) {<br \/>\n            $(document).trigger(&#8216;ajax:updateCartItemQty&#8217;);<\/p>\n<p>            if (window.location.href === this.shoppingCartUrl) {<br \/>\n                window.location.reload(false);<br \/>\n            }<br \/>\n        }<br \/>\n        this._hideItemButton(elem);<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @param {HTMLElement} elem<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _removeItem: function (elem) {<br \/>\n        var itemId = elem.data(&#8216;cart-item&#8217;);<\/p>\n<p>        this._ajax(this.options.url.remove, {<br \/>\n            &#8216;item_id&#8217;: itemId<br \/>\n        }, elem, this._removeItemAfter);<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * Update content after item remove<br \/>\n     *<br \/>\n     * @param {Object} elem<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _removeItemAfter: function (elem) {<br \/>\n        var productData = this._getProductById(Number(elem.data(&#8216;cart-item&#8217;)));<\/p>\n<p>        if (!_.isUndefined(productData)) {<br \/>\n            $(document).trigger(&#8216;ajax:removeFromCart&#8217;, {<br \/>\n                productIds: [productData[&#8216;product_id&#8217;]]<br \/>\n            });<br \/>\n        }<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * Retrieves product data by Id.<br \/>\n     *<br \/>\n     * @param {Number} productId &#8211; product Id<br \/>\n     * @returns {Object|undefined}<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _getProductById: function (productId) {<br \/>\n        return _.find(customerData.get(&#8216;cart&#8217;)().items, function (item) {<br \/>\n            return productId === Number(item[&#8216;item_id&#8217;]);<br \/>\n        });<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * @param {String} url &#8211; ajax url<br \/>\n     * @param {Object} data &#8211; post data for ajax call<br \/>\n     * @param {Object} elem &#8211; element that initiated the event<br \/>\n     * @param {Function} callback &#8211; callback method to execute after AJAX success<br \/>\n     *\/<br \/>\n    _ajax: function (url, data, elem, callback) {<br \/>\n        $.extend(data, {<br \/>\n            &#8216;form_key&#8217;: $.mage.cookies.get(&#8216;form_key&#8217;)<br \/>\n        });<\/p>\n<p>        $.ajax({<br \/>\n            url: url,<br \/>\n            data: data,<br \/>\n            type: &#8216;post&#8217;,<br \/>\n            dataType: &#8216;json&#8217;,<br \/>\n            context: this,<\/p>\n<p>            \/** @inheritdoc *\/<br \/>\n            beforeSend: function () {<br \/>\n                elem.attr(&#8216;disabled&#8217;, &#8216;disabled&#8217;);<br \/>\n            },<\/p>\n<p>            \/** @inheritdoc *\/<br \/>\n            complete: function () {<br \/>\n                elem.attr(&#8216;disabled&#8217;, null);<br \/>\n            }<br \/>\n        })<br \/>\n            .done(function (response) {<br \/>\n                var msg;<\/p>\n<p>                if (response.success) {<br \/>\n                    callback.call(this, elem, response);<br \/>\n                } else {<br \/>\n                    msg = response[&#8216;error_message&#8217;];<\/p>\n<p>                    if (msg) {<br \/>\n                        alert({<br \/>\n                            content: msg<br \/>\n                        });<br \/>\n                    }<br \/>\n                }<br \/>\n            })<br \/>\n            .fail(function (error) {<br \/>\n                console.log(JSON.stringify(error));<br \/>\n            });<br \/>\n    },<\/p>\n<p>    \/**<br \/>\n     * Calculate height of minicart list<br \/>\n     *<br \/>\n     * @private<br \/>\n     *\/<br \/>\n    _calcHeight: function () {<br \/>\n        var self = this,<br \/>\n            height = 0,<br \/>\n            counter = this.options.minicart.maxItemsVisible,<br \/>\n            target = $(this.options.minicart.list),<br \/>\n            outerHeight;<\/p>\n<p>        self.scrollHeight = 0;<br \/>\n        target.children().each(function () {<\/p>\n<p>            if ($(this).find(&#8216;.options&#8217;).length &gt; 0) {<br \/>\n                $(this).collapsible();<br \/>\n            }<br \/>\n            outerHeight = $(this).outerHeight();<\/p>\n<p>            if (counter&#8211; &gt; 0) {<br \/>\n                height += outerHeight;<br \/>\n            }<br \/>\n            self.scrollHeight += outerHeight;<br \/>\n        });<\/p>\n<p>        target.parent().height(height);<br \/>\n    }<br \/>\n});<\/p>\n<p>return $.mage.sidebar;<br \/>\n});<\/p>\n<p>[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>vendor\\magento\\module-checkout\\view\\frontend\\web\\template\\minicart\\item\\default.html Copy to default.html app\\design\\yourvendor\\yourtheme\\Magento_Checkout\\web\\template\\minicart\\item\\default.html add + and &#8211; button as span tag in line number 74 and 84. Or&#8230;<\/p>\n","protected":false},"author":1,"featured_media":34,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3,1],"tags":[25,24,26],"class_list":["post-102","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento","category-php","tag-ajax","tag-magento2","tag-phtml"],"acf":[],"_links":{"self":[{"href":"https:\/\/atish.co.in\/index.php?rest_route=\/wp\/v2\/posts\/102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atish.co.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atish.co.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atish.co.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atish.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=102"}],"version-history":[{"count":10,"href":"https:\/\/atish.co.in\/index.php?rest_route=\/wp\/v2\/posts\/102\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/atish.co.in\/index.php?rest_route=\/wp\/v2\/posts\/102\/revisions\/472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/atish.co.in\/index.php?rest_route=\/wp\/v2\/media\/34"}],"wp:attachment":[{"href":"https:\/\/atish.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atish.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atish.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}