Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling inventory in online ordering system

Status
Not open for further replies.

monkle

Programmer
Joined
Feb 11, 2004
Messages
132
Location
US
I'm currently working on an onlne ordering system. I created a shopping cart using session variables, and the inventory is in an sql db. I'm trying to work out how to track the quantity in the database. For instance, I need to know how many of any given item are in the cart of person X, so that person Y knows that there aren't as many pieces available.

I was thinking that I could add a second quantity field in the db, with how many items are pending in people's carts, but the carts get destroyed when the session gets destroyed, and I would have to have some way of knowing that the session ended without ordering so that I could modify the pending quantity.

I've been thinking/working/researching on this for a while now, and I think I'm pretty well stumped. Insight greatly appreciated.
 
I would use user-written session-handling functions.

PHP allows you to write your own session-handling functions. For an example, see my FAQ in this forum: faq434-2037.

What I would do is store the actual shopping cart data in a table in the database, and store only the ID for that cart in my session variable.

Then I would write a custom session garbage-collection function which would, before garbage-collecting the session, look in the session data to be destroyed, fetch the card ID, and delete the cart from the database.

Then you can dynamically calculate the numbers you need, with the numbers being updated as carts are automatically destroyed.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top