How to prevent adding multiple restaurant food item in cart












-4














I'm working on food ordering android app where you can order food from multiple restaurants. I'm using sqlite datebase to save food item in cart and I'm facing a problem like if you have ordered food from restaurant A then you should not be able to add food items from restaurant B until you clear cart. So how can I do this?










share|improve this question






















  • Check what restaurant you're ordering from before adding a new item. Even if we wanted to we can't give you code, you haven't posted any for us to alter.
    – Gabe Sechan
    Nov 16 '18 at 20:47










  • I haven't written code yet. I'm like stuck here. I don't have any idea about how to code this. I'm using firebase wait I'll update answer with code
    – Prasen Wahane
    Nov 16 '18 at 21:12
















-4














I'm working on food ordering android app where you can order food from multiple restaurants. I'm using sqlite datebase to save food item in cart and I'm facing a problem like if you have ordered food from restaurant A then you should not be able to add food items from restaurant B until you clear cart. So how can I do this?










share|improve this question






















  • Check what restaurant you're ordering from before adding a new item. Even if we wanted to we can't give you code, you haven't posted any for us to alter.
    – Gabe Sechan
    Nov 16 '18 at 20:47










  • I haven't written code yet. I'm like stuck here. I don't have any idea about how to code this. I'm using firebase wait I'll update answer with code
    – Prasen Wahane
    Nov 16 '18 at 21:12














-4












-4








-4







I'm working on food ordering android app where you can order food from multiple restaurants. I'm using sqlite datebase to save food item in cart and I'm facing a problem like if you have ordered food from restaurant A then you should not be able to add food items from restaurant B until you clear cart. So how can I do this?










share|improve this question













I'm working on food ordering android app where you can order food from multiple restaurants. I'm using sqlite datebase to save food item in cart and I'm facing a problem like if you have ordered food from restaurant A then you should not be able to add food items from restaurant B until you clear cart. So how can I do this?







android android-studio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 20:39









Prasen Wahane

15




15












  • Check what restaurant you're ordering from before adding a new item. Even if we wanted to we can't give you code, you haven't posted any for us to alter.
    – Gabe Sechan
    Nov 16 '18 at 20:47










  • I haven't written code yet. I'm like stuck here. I don't have any idea about how to code this. I'm using firebase wait I'll update answer with code
    – Prasen Wahane
    Nov 16 '18 at 21:12


















  • Check what restaurant you're ordering from before adding a new item. Even if we wanted to we can't give you code, you haven't posted any for us to alter.
    – Gabe Sechan
    Nov 16 '18 at 20:47










  • I haven't written code yet. I'm like stuck here. I don't have any idea about how to code this. I'm using firebase wait I'll update answer with code
    – Prasen Wahane
    Nov 16 '18 at 21:12
















Check what restaurant you're ordering from before adding a new item. Even if we wanted to we can't give you code, you haven't posted any for us to alter.
– Gabe Sechan
Nov 16 '18 at 20:47




Check what restaurant you're ordering from before adding a new item. Even if we wanted to we can't give you code, you haven't posted any for us to alter.
– Gabe Sechan
Nov 16 '18 at 20:47












I haven't written code yet. I'm like stuck here. I don't have any idea about how to code this. I'm using firebase wait I'll update answer with code
– Prasen Wahane
Nov 16 '18 at 21:12




I haven't written code yet. I'm like stuck here. I don't have any idea about how to code this. I'm using firebase wait I'll update answer with code
– Prasen Wahane
Nov 16 '18 at 21:12












1 Answer
1






active

oldest

votes


















0














As you haven't provided any code so here is one of the approach:



One option is that whenever user clicks on Add-to-Cart button. You can take the Id of that product's restaurant and save it somewhere like in SharedPreference and then check on every Add-to-Cart button click that whether this product's restaurant Id matches with the already saved Id? if yes ! proceed with adding this product to cart otherwise clear the cart or show the error message.



Note: Id here refers to the restaurantId and not the productId



For Example:



You will set the default value to the restaurentId as "" empty string or whatever you like and the checks will be like:



  if(restaurantId.equals("savedRestId") || savedRestId.equals(""){
//add product to cart
//save the restaurentId of the product
} else {
//error message
}


Description:



if restaurentId equals to the savedRestaurentId OR the savedRestaurentId equals default value "" then add the product in cart and save the restaurentId of that product else Error






share|improve this answer























  • I have same thing in my mind :)
    – Prasen Wahane
    Nov 17 '18 at 6:26










  • If( restaurantid.equals("savedRestid"){ //add to database} else { //error message}
    – Prasen Wahane
    Nov 17 '18 at 6:28












  • What should be the condition for the first time when user click add-to-cart button...
    – Prasen Wahane
    Nov 17 '18 at 6:33










  • @PrasenWahane I have updated the answer kindly check if that can help !
    – Muhammad waris
    Nov 17 '18 at 8:53










  • i have checkd but that is not working. Please take a look at weight android app where It won't let you add food in cart if you have food from other restaurant. I want something like that
    – Prasen Wahane
    Nov 17 '18 at 10:14











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%2f53345062%2fhow-to-prevent-adding-multiple-restaurant-food-item-in-cart%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














As you haven't provided any code so here is one of the approach:



One option is that whenever user clicks on Add-to-Cart button. You can take the Id of that product's restaurant and save it somewhere like in SharedPreference and then check on every Add-to-Cart button click that whether this product's restaurant Id matches with the already saved Id? if yes ! proceed with adding this product to cart otherwise clear the cart or show the error message.



Note: Id here refers to the restaurantId and not the productId



For Example:



You will set the default value to the restaurentId as "" empty string or whatever you like and the checks will be like:



  if(restaurantId.equals("savedRestId") || savedRestId.equals(""){
//add product to cart
//save the restaurentId of the product
} else {
//error message
}


Description:



if restaurentId equals to the savedRestaurentId OR the savedRestaurentId equals default value "" then add the product in cart and save the restaurentId of that product else Error






share|improve this answer























  • I have same thing in my mind :)
    – Prasen Wahane
    Nov 17 '18 at 6:26










  • If( restaurantid.equals("savedRestid"){ //add to database} else { //error message}
    – Prasen Wahane
    Nov 17 '18 at 6:28












  • What should be the condition for the first time when user click add-to-cart button...
    – Prasen Wahane
    Nov 17 '18 at 6:33










  • @PrasenWahane I have updated the answer kindly check if that can help !
    – Muhammad waris
    Nov 17 '18 at 8:53










  • i have checkd but that is not working. Please take a look at weight android app where It won't let you add food in cart if you have food from other restaurant. I want something like that
    – Prasen Wahane
    Nov 17 '18 at 10:14
















0














As you haven't provided any code so here is one of the approach:



One option is that whenever user clicks on Add-to-Cart button. You can take the Id of that product's restaurant and save it somewhere like in SharedPreference and then check on every Add-to-Cart button click that whether this product's restaurant Id matches with the already saved Id? if yes ! proceed with adding this product to cart otherwise clear the cart or show the error message.



Note: Id here refers to the restaurantId and not the productId



For Example:



You will set the default value to the restaurentId as "" empty string or whatever you like and the checks will be like:



  if(restaurantId.equals("savedRestId") || savedRestId.equals(""){
//add product to cart
//save the restaurentId of the product
} else {
//error message
}


Description:



if restaurentId equals to the savedRestaurentId OR the savedRestaurentId equals default value "" then add the product in cart and save the restaurentId of that product else Error






share|improve this answer























  • I have same thing in my mind :)
    – Prasen Wahane
    Nov 17 '18 at 6:26










  • If( restaurantid.equals("savedRestid"){ //add to database} else { //error message}
    – Prasen Wahane
    Nov 17 '18 at 6:28












  • What should be the condition for the first time when user click add-to-cart button...
    – Prasen Wahane
    Nov 17 '18 at 6:33










  • @PrasenWahane I have updated the answer kindly check if that can help !
    – Muhammad waris
    Nov 17 '18 at 8:53










  • i have checkd but that is not working. Please take a look at weight android app where It won't let you add food in cart if you have food from other restaurant. I want something like that
    – Prasen Wahane
    Nov 17 '18 at 10:14














0












0








0






As you haven't provided any code so here is one of the approach:



One option is that whenever user clicks on Add-to-Cart button. You can take the Id of that product's restaurant and save it somewhere like in SharedPreference and then check on every Add-to-Cart button click that whether this product's restaurant Id matches with the already saved Id? if yes ! proceed with adding this product to cart otherwise clear the cart or show the error message.



Note: Id here refers to the restaurantId and not the productId



For Example:



You will set the default value to the restaurentId as "" empty string or whatever you like and the checks will be like:



  if(restaurantId.equals("savedRestId") || savedRestId.equals(""){
//add product to cart
//save the restaurentId of the product
} else {
//error message
}


Description:



if restaurentId equals to the savedRestaurentId OR the savedRestaurentId equals default value "" then add the product in cart and save the restaurentId of that product else Error






share|improve this answer














As you haven't provided any code so here is one of the approach:



One option is that whenever user clicks on Add-to-Cart button. You can take the Id of that product's restaurant and save it somewhere like in SharedPreference and then check on every Add-to-Cart button click that whether this product's restaurant Id matches with the already saved Id? if yes ! proceed with adding this product to cart otherwise clear the cart or show the error message.



Note: Id here refers to the restaurantId and not the productId



For Example:



You will set the default value to the restaurentId as "" empty string or whatever you like and the checks will be like:



  if(restaurantId.equals("savedRestId") || savedRestId.equals(""){
//add product to cart
//save the restaurentId of the product
} else {
//error message
}


Description:



if restaurentId equals to the savedRestaurentId OR the savedRestaurentId equals default value "" then add the product in cart and save the restaurentId of that product else Error







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 8:52

























answered Nov 16 '18 at 21:21









Muhammad waris

13717




13717












  • I have same thing in my mind :)
    – Prasen Wahane
    Nov 17 '18 at 6:26










  • If( restaurantid.equals("savedRestid"){ //add to database} else { //error message}
    – Prasen Wahane
    Nov 17 '18 at 6:28












  • What should be the condition for the first time when user click add-to-cart button...
    – Prasen Wahane
    Nov 17 '18 at 6:33










  • @PrasenWahane I have updated the answer kindly check if that can help !
    – Muhammad waris
    Nov 17 '18 at 8:53










  • i have checkd but that is not working. Please take a look at weight android app where It won't let you add food in cart if you have food from other restaurant. I want something like that
    – Prasen Wahane
    Nov 17 '18 at 10:14


















  • I have same thing in my mind :)
    – Prasen Wahane
    Nov 17 '18 at 6:26










  • If( restaurantid.equals("savedRestid"){ //add to database} else { //error message}
    – Prasen Wahane
    Nov 17 '18 at 6:28












  • What should be the condition for the first time when user click add-to-cart button...
    – Prasen Wahane
    Nov 17 '18 at 6:33










  • @PrasenWahane I have updated the answer kindly check if that can help !
    – Muhammad waris
    Nov 17 '18 at 8:53










  • i have checkd but that is not working. Please take a look at weight android app where It won't let you add food in cart if you have food from other restaurant. I want something like that
    – Prasen Wahane
    Nov 17 '18 at 10:14
















I have same thing in my mind :)
– Prasen Wahane
Nov 17 '18 at 6:26




I have same thing in my mind :)
– Prasen Wahane
Nov 17 '18 at 6:26












If( restaurantid.equals("savedRestid"){ //add to database} else { //error message}
– Prasen Wahane
Nov 17 '18 at 6:28






If( restaurantid.equals("savedRestid"){ //add to database} else { //error message}
– Prasen Wahane
Nov 17 '18 at 6:28














What should be the condition for the first time when user click add-to-cart button...
– Prasen Wahane
Nov 17 '18 at 6:33




What should be the condition for the first time when user click add-to-cart button...
– Prasen Wahane
Nov 17 '18 at 6:33












@PrasenWahane I have updated the answer kindly check if that can help !
– Muhammad waris
Nov 17 '18 at 8:53




@PrasenWahane I have updated the answer kindly check if that can help !
– Muhammad waris
Nov 17 '18 at 8:53












i have checkd but that is not working. Please take a look at weight android app where It won't let you add food in cart if you have food from other restaurant. I want something like that
– Prasen Wahane
Nov 17 '18 at 10:14




i have checkd but that is not working. Please take a look at weight android app where It won't let you add food in cart if you have food from other restaurant. I want something like that
– Prasen Wahane
Nov 17 '18 at 10:14


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53345062%2fhow-to-prevent-adding-multiple-restaurant-food-item-in-cart%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

How to change which sound is reproduced for terminal bell?

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

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents