ngCart
ngCart copied to clipboard
Updating quantities of ngCartItem does not save to LocalStorage.
trafficstars
I am trying to add some Plus and Minus buttons to increase and decrease the item quantity in the cart directly. This is what I got, and it all works fine and dandy, the cart gets updated and all, but when I check localStorage, my item quantities are not changed.
let ctrl = ['$scope', 'bottles', 'ngCart', ($scope, bottles, ngCart) => {
"use strict";
$scope.viewClass = 'shopView'
$scope.bottles = bottles;
$scope.cart = {
increaseQuantity: (slug)=> {
let item = ngCart.getItemById(slug);
if(typeof item === 'object'){
item.setQuantity(1,true);
} else {
let bottle = bottles[slug];
ngCart.addItem(bottle.slug,bottle.name,bottle.price,1);
}
},
decreaseQuantity: (slug)=> {
let item = ngCart.getItemById(slug);
if(item){
if(item.getQuantity() > 1){
item.setQuantity(-1,true);
} else {
ngCart.removeItemById(slug)
}
} else {
return false;
}
},
getCurrentQuantity: (slug)=> {
//console.log(slug);
let item = ngCart.getItemById(slug);
return item ? item.getQuantity() : 0;
}
}
}];
Funny thing is, when I try to use the provided add-to-cart directive, it all works. If I try to edit the quantities from the cart directive, I still have the same problem... I just dont get my localstorage updated after 1 element quantity is added.
1.0.0 Commit After this update, there is no ngCart:change event, so the Cart and the localStorate is not Updated...