February 2015
Intermediate to advanced
232 pages
4h 40m
English
To update the component with new namespaces, update (overwrite) the references to the dependencies, as follows:
ko.components.register('add-to-cart-button', {
viewModel: function(params) {
this.item = params.item;
this.cart = params.cart;
this.addToCart = function() {
var CartProduct = Shop.Models.CartProduct;
var CartProductService = Shop.Services.CartProductService;
var ProductService = Shop.Services.ProductService; var data = this.item; var tmpCart = this.cart(); var n = tmpCart.length; var item = null; if(data.stock()<1) { return; } while(n--) { if (tmpCart[n].product.id() === data.id()) { item = tmpCart[n]; } } if (item) { CartProductService.addUnit(item); } else { item = CartProduct(data,1); tmpCart.push(item); ...Read now
Unlock full access