Updating the add-to-cart-button component

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); ...

Get KnockoutJS Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.