Requirement
Add a new removal icon to each individual item cell of the mini cart. When the icon is clicked, the item should be removed from the mini cart and the cart page
Solution
events: {
'click [data-action="remove-item"]': "removeItem",
}
removeItem: function removeItem(e) {
var self = this;
var currentitemid = this.$(e.target).data('internalid');
var array = self.model.get('lines').models;
var foundIndex = array.findIndex((el) => (el.cartitemid === currentitemid));
var product = self.model.get('lines').models[foundIndex]
var remove_promise = self.model.removeLine(product);
var internalid = product.get('cartitemid');
this.isRemoving = true;
this.disableElementsOnPromise(
remove_promise,
`article[id="${internalid}"] a, article[id="${internalid}"] button`
);
remove_promise.always(function () {
self.isRemoving = false;
});
return true;
},