[thelist] Backend of a shopping cart system...

Chris Blessing webguy at mail.rit.edu
Fri Apr 5 10:16:02 CST 2002


Hehehe, very good sir.  Thanks a ton for the information.  Good stuff for
sure and I will certainly get my flow chart on before tackling this project.

Thanks!!

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net

> The customer ID should never change.  Each user should be a row in your
> Customer table, and every one should have a unique ID.  You may opt to
> also use Session ID's, and if so, there will be a new one each time a
> user returns.
>
> Here's the question:  When a user addes an item to a cart, and you don't
> know who he is, how do you handle that item?
>
> Here's the logic I use behind my "Add to Cart" buttons:
>
> - Does this user have a cookie with their Customer ID?
>
> -- If YES, then grab their Customer ID from the cookie and store it in a
> variable.
>
> -- If NO, then do they already have a cookie with a Temporary ID? (keep
> reading).
>
> --- If Yes, then grab that ID and store it in a variable.
>
> --- If NO, then then create a unique Temporary ID, store it in a
> variable, and create a cookie with that ID
>
> - If we did NOT just create a new Temp ID then (there is the possibility
> that this item already exists in their cart)
>
> -- Does this user already have items in his cart?
>
> -- If YES then
>
> --- Is this particular item already in the user's cart?
>
> ---- If YES then add 1 to the Quantity column
>
> ELSE ELSE ELSE: create a new row, add the Product ID and either the
> Customer ID in the CID field or the Tempo ID in the TID field, and what
> other data you wish to store (date, time, etc.)
>
>
> For Temporary ID's I use the user's IP Address plus a uniquely generated
> ID which is simply the last Temp ID+1.
>
> Now, even if you don't know who the user is, his items in the cart have
> a unique id that at least identifies them as his.  When he goes to check
> out, you now follow this logic:
>
> Do the items in his cart have a Customer ID or Temp ID?
>
> - If TID, then:
>
> -- Has this user been here before? (Once the user begins the check out
> process, run his data against known previous customers.)
>
> --- If YES, then grab his Customer ID and add it to the items in CART
> which have his Temp ID.  His Temp ID is now defunt, which is why it is
> called a Temporary ID.
>
> --- If No, then create a new and unique Cust ID and add that ID to each
> items in his cart.  The Temp ID is now defunt.
>
> - If CID, then: (There is the possibility that last time he was here he
> added items to his cart and then abondned that cart.  Now he has come
> back, and before we knew who he was, he added more items.  You have to
> decide how / if you want to handle old items in abonded carts.  It will
> be easiest to simply ignore them.)
>
> Proceed with check out.
>
> As you can see, if is a complicated process with many forks in the road,
> but all forks must eventually come back together.  My advice is to sit
> down and plan out the enitre process on paper -- use a good old
> fashioned flow chart.
>
> More advice: USE COOKIES!!!
>
> HTH,
>
> Casey




More information about the thelist mailing list