Shopping cart + Storage + add and remove quantity for specific item in ionic 3












0















I am working on this shopping cart module for one of my projects and this is the first time I am working on feature lie Shopping cart. Here I have a button for every item and once I click on one item I want to display the + and - buttons in order to increase/decrease the quantity for that specific item.
Now what is happening in my scenario is I am able to display buttons for all items u I am failing to add a specific item, it adds all the items and if i go to remove it doesn't do anything (It reflects all items), and quantity for that item needs to be stored/removed/updated locally. Here is my code snippets.



my .ts file



   addQuantity(quantity,counter){
for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter += counter;
console.log(this.storageValue[key].count);
return;
}
this.counter = this.counter+1;
this.quantities.push(quantity[key]);
console.log(this.quantities.push(quantity[key]));
}
}

subQuantity(quantity,counter){

for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter--;
console.log(this.storageValue[key].counter--);
if(this.storageValue[key]){

}
break;
}

console.log(this.storageValue[key].counter--);

}

}

}


my html file



<ion-content>
<ion-icon name="add-circle" (click)="addQuantity(displayItems.ITEMID)" item-right></ion-icon>
{{counter}}
<ion-icon name="remove-circle"(click)="subQuantity(displayItems.ITEMID)" item-right></ion-icon>

</div>

<div *ngIf="!alive">
<button ion-button item-end (click)="alive = !alive">Add</button>
</div>
<!-- Customisable -->
</div>
</ion-item>






I am a beginner and learning Ionic. Your guidance will be appreciated.










share|improve this question




















  • 1





    Could you show what this.storageValue looks like ?

    – saperlipopette
    Nov 22 '18 at 8:32











  • its just storageValue:number;

    – shashank verma
    Nov 22 '18 at 9:43
















0















I am working on this shopping cart module for one of my projects and this is the first time I am working on feature lie Shopping cart. Here I have a button for every item and once I click on one item I want to display the + and - buttons in order to increase/decrease the quantity for that specific item.
Now what is happening in my scenario is I am able to display buttons for all items u I am failing to add a specific item, it adds all the items and if i go to remove it doesn't do anything (It reflects all items), and quantity for that item needs to be stored/removed/updated locally. Here is my code snippets.



my .ts file



   addQuantity(quantity,counter){
for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter += counter;
console.log(this.storageValue[key].count);
return;
}
this.counter = this.counter+1;
this.quantities.push(quantity[key]);
console.log(this.quantities.push(quantity[key]));
}
}

subQuantity(quantity,counter){

for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter--;
console.log(this.storageValue[key].counter--);
if(this.storageValue[key]){

}
break;
}

console.log(this.storageValue[key].counter--);

}

}

}


my html file



<ion-content>
<ion-icon name="add-circle" (click)="addQuantity(displayItems.ITEMID)" item-right></ion-icon>
{{counter}}
<ion-icon name="remove-circle"(click)="subQuantity(displayItems.ITEMID)" item-right></ion-icon>

</div>

<div *ngIf="!alive">
<button ion-button item-end (click)="alive = !alive">Add</button>
</div>
<!-- Customisable -->
</div>
</ion-item>






I am a beginner and learning Ionic. Your guidance will be appreciated.










share|improve this question




















  • 1





    Could you show what this.storageValue looks like ?

    – saperlipopette
    Nov 22 '18 at 8:32











  • its just storageValue:number;

    – shashank verma
    Nov 22 '18 at 9:43














0












0








0








I am working on this shopping cart module for one of my projects and this is the first time I am working on feature lie Shopping cart. Here I have a button for every item and once I click on one item I want to display the + and - buttons in order to increase/decrease the quantity for that specific item.
Now what is happening in my scenario is I am able to display buttons for all items u I am failing to add a specific item, it adds all the items and if i go to remove it doesn't do anything (It reflects all items), and quantity for that item needs to be stored/removed/updated locally. Here is my code snippets.



my .ts file



   addQuantity(quantity,counter){
for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter += counter;
console.log(this.storageValue[key].count);
return;
}
this.counter = this.counter+1;
this.quantities.push(quantity[key]);
console.log(this.quantities.push(quantity[key]));
}
}

subQuantity(quantity,counter){

for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter--;
console.log(this.storageValue[key].counter--);
if(this.storageValue[key]){

}
break;
}

console.log(this.storageValue[key].counter--);

}

}

}


my html file



<ion-content>
<ion-icon name="add-circle" (click)="addQuantity(displayItems.ITEMID)" item-right></ion-icon>
{{counter}}
<ion-icon name="remove-circle"(click)="subQuantity(displayItems.ITEMID)" item-right></ion-icon>

</div>

<div *ngIf="!alive">
<button ion-button item-end (click)="alive = !alive">Add</button>
</div>
<!-- Customisable -->
</div>
</ion-item>






I am a beginner and learning Ionic. Your guidance will be appreciated.










share|improve this question
















I am working on this shopping cart module for one of my projects and this is the first time I am working on feature lie Shopping cart. Here I have a button for every item and once I click on one item I want to display the + and - buttons in order to increase/decrease the quantity for that specific item.
Now what is happening in my scenario is I am able to display buttons for all items u I am failing to add a specific item, it adds all the items and if i go to remove it doesn't do anything (It reflects all items), and quantity for that item needs to be stored/removed/updated locally. Here is my code snippets.



my .ts file



   addQuantity(quantity,counter){
for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter += counter;
console.log(this.storageValue[key].count);
return;
}
this.counter = this.counter+1;
this.quantities.push(quantity[key]);
console.log(this.quantities.push(quantity[key]));
}
}

subQuantity(quantity,counter){

for (var key in this.storageValue){
if(this.storageValue[key] === quantity){
this.storageValue[key].counter--;
console.log(this.storageValue[key].counter--);
if(this.storageValue[key]){

}
break;
}

console.log(this.storageValue[key].counter--);

}

}

}


my html file



<ion-content>
<ion-icon name="add-circle" (click)="addQuantity(displayItems.ITEMID)" item-right></ion-icon>
{{counter}}
<ion-icon name="remove-circle"(click)="subQuantity(displayItems.ITEMID)" item-right></ion-icon>

</div>

<div *ngIf="!alive">
<button ion-button item-end (click)="alive = !alive">Add</button>
</div>
<!-- Customisable -->
</div>
</ion-item>






I am a beginner and learning Ionic. Your guidance will be appreciated.







ionic3 shopping-cart ionic-storage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 7:37







shashank verma

















asked Nov 22 '18 at 4:33









shashank vermashashank verma

146




146








  • 1





    Could you show what this.storageValue looks like ?

    – saperlipopette
    Nov 22 '18 at 8:32











  • its just storageValue:number;

    – shashank verma
    Nov 22 '18 at 9:43














  • 1





    Could you show what this.storageValue looks like ?

    – saperlipopette
    Nov 22 '18 at 8:32











  • its just storageValue:number;

    – shashank verma
    Nov 22 '18 at 9:43








1




1





Could you show what this.storageValue looks like ?

– saperlipopette
Nov 22 '18 at 8:32





Could you show what this.storageValue looks like ?

– saperlipopette
Nov 22 '18 at 8:32













its just storageValue:number;

– shashank verma
Nov 22 '18 at 9:43





its just storageValue:number;

– shashank verma
Nov 22 '18 at 9:43












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423941%2fshopping-cart-storage-add-and-remove-quantity-for-specific-item-in-ionic-3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423941%2fshopping-cart-storage-add-and-remove-quantity-for-specific-item-in-ionic-3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?