How to determine if visitor has decided not to buy items in cart?

I have a website that allows purchasing by paypal. I sell items that are finite in quantity for each item, and that means the code has to be carefully structured to prevent 2 people from simultaneously buying the same item (for example, someone could get as far as logging into paypal, and then do nothing for a half hour while someone else could complete the entire process), since there could be only 1 left.

My solution has been to add a column to my inventory tables called “hold”. As soon as a user adds an item to the cart, it increments the hold cell for that item. When checking to see if a person can add the item, it requires that (inventory-hold)>0. Then, when I get around to processing things, if I complete an order I can take 1 off the hold value and also take 1 off the inventory. And if they remove items from the cart, of course it also takes the item off hold.

The problem is that I’m not really sure what to do if someone adds items to the cart, but then decides to just close the browser and never come back. How would I know that they’ve done that? This is in fact likely to happen quite often, and would result things sitting on hold indefinitely with no way for me to know that they’ve been abandoned. And that is a problem because it would eventually lead to items being unavailable for purchase even though they are available in inventory.

The site is PHP+mySQL, with some Javascript as well. The cart is handled with PHP Sessions (there’s no user log-in).

How can I solve this problem? Is there some way I can put a “time limit” when something is added to the cart, and if it’s not purchased within that time, it’s taken back out of cart (and off hold)? It would have to be a server-side clock of some kind, so that it continues to run and perform changes to the database even when nobody is on the site. Can that be done? I am still pretty new to this, maybe a dumb question…

You can write a session handler…

http://us2.php.net/session_set_save_handler

But, I generally, let people add everything they want to a cart and when they go to the checkout screen, if it’s sold they get a (Item not in stock, or Item is on back order).

I would run a “Check Stock” routine, right before you charge their credit card and if the item is sold, then don’t charge them and let them adjust as needed.

The problem you are facing is that you’re using paypal instead of a merchant service and you have to wait till get you get an IPN notice back from paypal and process that IPN, so you won’t actually know if it’s sold until you get an an IPN back from ebay which sometimes takes up to 5 minutes. A Merchant service is usually within seconds, you’ll get an accept or denial.

If you’re savvy with php, look at some of the popular shopping carts that are open source, like oscommerce, magneto and see how they handle those conditions and ask on those forums as well.

You also want to save the abandoned carts, most e-commerence software allows you to send emails to those people offering discounts on the items in their carts, trying to entice them to buy it.

Sponsor our Newsletter | Privacy Policy | Terms of Service