From a9fdd8d516a571c33dd19a27d5ad4dbaee3d47d8 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 20 Apr 2022 21:54:35 +1000 Subject: [PATCH] chap2 -> Creating templates -> The cart-item template --- ko-cart/index.html | 22 +++++++++++++++++++++- ko-cart/js/viewmodel.js | 10 +++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ko-cart/index.html b/ko-cart/index.html index 3e6a8dc..a67ca75 100644 --- a/ko-cart/index.html +++ b/ko-cart/index.html @@ -131,7 +131,27 @@ Total Items: Price: - + diff --git a/ko-cart/js/viewmodel.js b/ko-cart/js/viewmodel.js index dcd391f..02a3cc4 100644 --- a/ko-cart/js/viewmodel.js +++ b/ko-cart/js/viewmodel.js @@ -83,6 +83,13 @@ var vm = (function () { return total; }) + var removeFromCart = function (data) { + var units = data.units(); + var stock = data.product.stock(); + data.product.stock(units + stock); + cart.remove(data); + } + return { // first chapter searchTerm: searchTerm, @@ -93,7 +100,8 @@ var vm = (function () { cart: cart, showCartDetails: showCartDetails, totalItems: totalItems, - grandTotal: grandTotal + grandTotal: grandTotal, + removeFromCart: removeFromCart }; })(); ko.applyBindings(vm);