How would I set up a shopping cart to do this?

Discussion in 'PHP' started by sjaguar13, Jan 30, 2007.

  1. #1
    How would I make a shopping cart that you can add products to, but would also let you add a custom made CD. The CD would then allow you to add songs to it. The cost of the custom CD would be a base price for the CD and then a cost per song. I looked at a few shopping carts, and they either use sessions to store all the info, or a session ID to identify items in a database.

    If I use sessions and make an array of all products added, would I use another session variable with all the songs added? I need to know the order the songs should be burned on the CD, too. The problem I see with this way is what happens if someone buys multiple CDs? Would I create an array to hold the songs, and then an array of those arrays for multiple CDs?

    If I used a database, it makes things a little easier. All items would be added to a table along with the session id to identify the user who owns the cart. Then I have another table for the songs. When a CD is added to the cart table, it also inserts a CD_ID. Then all the songs are added with the owner (the session id), the CD_ID (to keep track of multiple CDs ordered), the song_id, and then the track number the song should be on the CD. The problem with this is, if a user makes the CD and then logs in, how do I change the session id over to the user, or would the session id still be the same? I don't want the CD going away just because the window was closed. Also, how would I know when the session id is no longer being used by someone, and all items can be removed from the table?
     
    sjaguar13, Jan 30, 2007 IP
  2. sharpweb

    sharpweb Guest

    Messages:
    246
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'd use a database, but instead of tracking users through sessionids, I'd make them login before adding songs to their CD and track them with their userid. That way when a user logs back in you just look up their userid in the database and find the songs they had on their CD.

    If you don't want to make them login first, just set a cookie so that you know who they are next time they come visit. Add the cookie number to the database instead.

    hope that helps
     
    sharpweb, Jan 30, 2007 IP
  3. Kalyse

    Kalyse Peon

    Messages:
    1,221
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thats exactly the way i do it with my game servers
     
    Kalyse, Jan 30, 2007 IP
  4. sjaguar13

    sjaguar13 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's what I planned on doing with the session ID because they would be unique. However I generate a number for a cookie has the chance of being a duplicate.
     
    sjaguar13, Jan 30, 2007 IP
  5. Kalyse

    Kalyse Peon

    Messages:
    1,221
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Why will it be unique?

    When I need a unique ID.

    I do

    $_SESSION['userid'] . time()

    Invoice codes are made like that for me.

    $invoice = "x" . $_SESSION['userid'] . "x" . time();

    Can you not do something equivalent?
     
    Kalyse, Jan 30, 2007 IP