Mini cart – Remove all items

Requirement

Add a button to remove all items from mini cart

Solution

_.extend(HeaderMiniCartView.prototype, {
events: {
	'click [data-action="clear-all"]': "clearAll",
       }
},
clearAll: function clearAll() {
     var self = this;
     var itemarray = this.model.get('lines').models;

     for (let i = 0; i < itemarray.length; i++) {
	if (itemarray[i].cartitemid) {
	 var arrayitems = itemarray[i];
	 var remove_promise = self.model.removeLine(arrayitems);
		}
	   }
    return true;
       }

Leave a comment

Your email address will not be published. Required fields are marked *