[thelist] Re: Homemade Shopping Cart Question

Hassan Schroeder hassan at webtuitive.com
Tue Nov 25 10:51:10 CST 2003


Kevin Martin wrote:

> I'll show you mine if you show me yours.  :-)

Hold that thought -- I could probably clean it up a bit and post
the code somewhere, but...

> My build-a-webstore page talks about taking stuff off the shelf
> and putting it back in some detail -- dig into the walk-through
> at http://simpleshop.org/

Ah. PHP. Mine's written in Java and -- more significantly -- runs
in a servlet container (Tomcat) that handles connection pooling and
session management. And when I say "cart", it's one Java class, it
has no display code, it only has methods to add to, delete from, or
list its contents. SimpleShoPHP seems to include all the code to
display things as well -- very different.

So the actual code may not be that useful.

The conceptual basis is simple, though. The inventory table has an
"availability" field with three states: it's here, it's gone to a
specific purchaser, it's in a specific shopping cart :-)  like so:

   +--------------+---------+----------
   | availability | product | ...
   +--------------+---------+----------
   |  available   | 123456  |
   +--------------+---------+----------
   |  C7812987128 | 323457  |  /* C for cart id, P for purchase
   +--------------+---------+-- * transaction --
   |  P2003101501 | 234678  |   * you get the idea ...
   +--------------+---------+---*/


The other major conceptual difference between my cart implementation
and most (including SimpleShoPHP) is that it's specifically for unique
or very-low-quantity items, so each *item* has it's own unique ID,
rather than being represented by a SKU and a quantity field.

In other words, each row in the inventory table represents an actual
physical item. You wouldn't want to do this for stovebolt inventory
at the hardware store :-)

If I were in that situation, I'd probably store the cart contents in
a HashMap in session scope and decrement or increment the quantity
fields in the DB. The process in <http://simpleshop.org/tyvm-indepth.php>
seems a little convoluted (at least at a quick glance). YMMV.

Hope that's useful!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.





More information about the thelist mailing list