Removing Items from the cart removeAll Function Removes all the items from the cart page, add action while clicking a link or button on the cart page to remove the buttons
removeAll: function removeAll(container) {
var application = container;
var cart = application.getComponent("Cart");
cart.getLines().then(lines => {
if (lines.length > 0) {
var removeAllLinesConfirmationView = new GlobalViewsConfirmationView({
callBack: this._removeAll,
// If the user confirms, this is the function that's called
// Note that we just put its name, not this._removeAll() (ie with its brackets)
title: _("Remove All Items").translate(),
body: _(
"Are you sure you want to remove all items from your cart?"
).translate(),
autohide: true,
});
// Use the layout component to create the modal dialog
// and then use this.options.application.getLayout().showInModal(removeAllLinesConfirmationView);
application.getLayout().showInModal(removeAllLinesConfirmationView)
} else {
alert(_("You have nothing in your cart to remove.").translate());
}
})
},
_removeAll: function _removeAll() {
var model = LiveOrderModel.getInstance();
// The model we use for cart contents is a singleton
// One, and only one, version of it may exist throughout the whole site
// Trigger the DELETE request and then re-render the page with whatever it sends back (it should be empty!)
return model.destroy().done(function (attributes) {
model.set(attributes);
});
}