einen Dienst zu reinigen habe ich einen Dienst, der wie folgt aussieht (Sie können es aus einem Einkaufswagen sehen.)Wie am Ende seiner Verwendung in Ionic/AngularJS
Ich versuche/entfernen zurücksetzen diesen Warenkorb mit einem Knopf (Kaufen Sie mehr neue Artikel "), um eine neue Bestellung zu machen, aber die Menge der vor der Bestellung geht es weiter, und wann immer es einen neuen Kaufauftrag macht, Summe mit der vorherigen Bestellmenge.Ich versuche zu resetten/entfernen Sie diesen Warenkorb mit einem Knopf (Kaufen Sie mehr neue Artikel), um eine neue Bestellung zu machen, aber die Menge der Vorbestellung geht weiter, und wann immer es eine neue Kaufbestellung macht, summieren Sie sich mit der vorherigen Bestellmenge.
Es ist der Dienst so die korrekte am Ende, es zu sagen ist verwendet:
angular.module('nhaac.services', [])
.factory('sharedCartService', ['$ionicPopup',function($ionicPopup){
// OKAY, MAS ONDE ELE ESTÁ PEGANDO?
// DECLARA AS VARIÁVEIS
var cartObj = {};
cartObj.cart=[];
cartObj.total_amount=0;
cartObj.total_qty=0;
// VERIFICA DE JÁ EXISTE ITENS NO CARRINHO
cartObj.cart.add=function(id,image,name,price,qty,supply_id,deliver){
if(cartObj.cart.find(id)!=-1 ){
var alertPopup = $ionicPopup.alert({
title: 'Este produto já foi Adicionado',
template: 'Acrescente mais quantidade abaixo da oferta no carrinho'
});
// }if (CartObj, { 'cart_item_supply': supply_id}) {
}if (cartObj.cart.findvovo(supply_id) !=-1){
var alertPopup = $ionicPopup.alert({
title: "Você só pode comprar de uma única Vovó por vez",
template: "Volte ao carrinho e escolha a opção COMPRAR MAIS DELICIAS."
});
}else{
cartObj.cart.push({ "cart_item_id": id , "cart_item_image": image , "cart_item_name": name , "cart_item_price": price , "cart_item_qty": qty, "cart_item_supply": supply_id, "cart_item_deliver": deliver });
cartObj.total_qty+=1;
cartObj.total_amount+=parseInt(price);
console.log(cartObj);
}
};
// PROCURA PRODUTOS NO CARRINHO PELO ID
cartObj.cart.find=function(id){
var result=-1;
for(var i = 0, len = cartObj.cart.length; i < len; i++) {
if(cartObj.cart[i].cart_item_id === id) {
result = i;
console.log(result);
break;
}
}
return result;
};
// PROCURA COD FORNECEDOR É IGUAL
cartObj.cart.findvovo=function(supply_id){
var result=-1;
for(var i = 0, len = cartObj.cart.length; i < len; i++) {
if(cartObj.cart[i].cart_item_supply === supply_id) {
result = i;
console.log('Qual Vovo achou '+result);
break;
}
};
return result;
};
// CLEAN CART
cartObj.cart.drop=function(id){
var temp=cartObj.cart[cartObj.cart.find(id)];
cartObj.total_qty-= parseInt(temp.cart_item_qty);
cartObj.total_amount-=(parseInt(temp.cart_item_qty) * parseInt(temp.cart_item_price));
window.localStorage.removeItem("fonecedor_carrinho",cartObj.supply_id);
cartObj.cart.splice(cartObj.cart.find(id), 1);
};
// ADD ITENS TO CART
cartObj.cart.increment=function(id){
cartObj.cart[cartObj.cart.find(id)].cart_item_qty+=1;
cartObj.total_qty+= 1;
cartObj.total_amount+=(parseInt(cartObj.cart[cartObj.cart.find(id)].cart_item_price));
};
// DIMINUI A QUANTIDADE DE ITENS NO CARRINHO
cartObj.cart.decrement=function(id){
cartObj.total_qty-= 1;
cartObj.total_amount-= parseInt(cartObj.cart[cartObj.cart.find(id)].cart_item_price) ;
if(cartObj.cart[cartObj.cart.find(id)].cart_item_qty == 1){ // if the cart item was only 1 in qty
cartObj.cart.splice(cartObj.cart.find(id) , 1); //edited
}else{
cartObj.cart[cartObj.cart.find(id)].cart_item_qty-=1;
}
};
console.log('chama return');
return cartObj;
}])
Sie können es aus einem Einkaufswagen sehen.
Ich versuche, diesen Dienst so zu löschen:
$scope.novoPedido = function() {
// CLEAN CART SHOP
var cart = sharedCartService.cart;
sharedCartService.cart.splice(0, sharedCartService.cart.length);
// sharedCartService.cart.drop("");
>> This dont work
// $state.go('novopedido');
};
Aber es die Menge nicht gelöscht, es löscht nur die Elemente, stuft die Menge, wie alles zu löschen, einschließlich der Menge? Ich weiß nicht, wie es geht ...
Vielen Dank!