Deleting a product
To delete a product, follow some simple steps as you did with the CREATE
and UPDATE
methods.
The first step is to create the mocks in the
mocks/products.js
file, as follows:$.mockjax({ url: /^\/products\/([\d]+)$/, type:'DELETE', dataType: 'json', responseTime: 750, status:200, responseText: { 'data': { text: 'Product deleted' } } });
This method is quite easy. Just add a button like the edit button and then the action to remove it.
var deleteProduct = function (product){ ProductResource.remove(product.id()) .done(function(response){ catalog.remove(product); filteredCatalog(catalog()); removeFromCartByProduct(product); }); };
Create a function to remove the product from the cart. This function iterates over the cart items and locates the cart item which is related to the removed product. Once this item is located, you can remove it as a normal item using the
removeFromCart
function:var removeFromCartByProduct = function (product...