Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:43:15+00:00 2026-06-06T22:43:15+00:00

I am developing an app with a shopping cart. When I add a product,

  • 0

I am developing an app with a shopping cart. When I add a product, I have to check if this product exist. I was using this method:

for (go over all products){

  if(product exists){

  --only change the quantity of the product[n]

  }
  else{

  --create a new product object with all its properties

  }

}

But with this method if the product I want to add don´t is the same with the index 0 (the first that the for checks), always add a new object (product) so if for example, my product exists and have the index 2, this for never will know that it exists.

Sorry for my english 😉 and thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:43:16+00:00Added an answer on June 6, 2026 at 10:43 pm

    If I understood it right, you’re problem is, that you loop over all the products and if the product is not the same as the new one, you just add a new one.

    but you’ll need to loop over all entries first and after you have done that and didn’t find anything, you create a new product.

    So in pseudo code:

    bool productExists = false;
    for every product {
        if(same product) {
            productExists = true
            change the quantity
            break;
        }    
    }
    if(!productExists) {
        add new product
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a java EE web app using JSF with a shopping cart style
im developing a app in Android. in this project im using a List of
I am developing app using the jquerymobile framework. I have to set the background
Developing ios app. I have an object class Product.h and .m respectively along with
I am developing an app on iPad which has only animations. I am using
We are developing a django app for several restaurants, it's like a shopping chart.
I am developing an ecommerce app that is using the UPS shipping webservice. I
I am developing app which add contact info to android contact list .to How
i am developing app in Blackberry which have GPS Functionality. so first i want
Am developing sample barcode scanner app. I using ZBar API to scan the barcode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.