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

Casey Crookston casey.crookston at imibevcore.com
Fri Apr 5 10:00:01 CST 2002


>>But again, once the user ends their session, I have no idea what their
customer id was nor do I know what it will be the next time they start a
session... right?<<

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





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

> Each time a user click's "Add to Cart" a record is added to your Cart
> table.  This table will have several key fields, one being unique to
> that row, one which relates back to the customer (a Customer ID) and
> one which relates back to the product (a Product ID).  Another colum
> would indicate the staus of this items in the cart.  Example 1=added
> but not purchased; 2=Added then deleted; 3=Added and purchased.  When
> that visitor comes back, your SQL statement which populates his cart
> will select all items from Cart where Customer ID = current and Status

> ID = 1.
>
> Other data in this table will record the date and time it was added or

> deleted or purchased, etc.
>
> HTH,
>
> Casey

--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !



More information about the thelist mailing list