Can the shopping cart automatically reset after a period of inactivity?

steeeeephensteeeeephen Member
in Help edited November 2007
Is it possible to have all the items removed from the shopping cart after a period of inactivity? Here's why I ask...
I think I've explained what Im trying to do in an earlier post on this forum, but in case I didn't and to recap, here it is again:
(For most of the products) the system I am setting up is for one-up items. Each item is unique (quantity 1) and can only be purchased once. So, to avoid people from purchasing two of the same item, here is the way I've got things going.
1. Somebody comes to the store. They find a product they want and click the "add to cart" link.
2. Before the item is added to the cart, an AJAX request is sent querying the database to check and make sure that the product is indeed still available.
3. If the product is indeed still available, another AJAX request is sent to the database, which puts a "lock" on the product, which will expire after a period (lets say 15 minutes) of inactivity based of the user's IP address. If the product is not available (it has either been sold or locked by a different user since the page initially loaded on our user's system) a message is displayed and the item is not added to the cart.
4. So, the user either completes the purchase and the status of the product is changed from "lock" to "sold", or 15 minutes go by, and the product's status changed back to "available".
But if the period of inactivity goes by, I would the cart to expire at the same time as the product's status switches back to unavailable.
I guess if that's not possible, I could just run a check everytime the cart opens that would check each item. If (after the period of inactivity) the item is still available (the status was reset and nobody else locked or purchased it) I would re-lock the item for the user, giving him a fresh new 15 minutes to buy it. If the item isn't available, I could show a message explaining they took too long and remove it from the cart. But, I would prefer to have the cart expire, it would be easier.
As a side note of something you might be interested in, I am using the data feed to get purchased items and change them from "lock" to "sold" in the database.
Comments
  • brettbrett FoxyCart Team
    Dude, that's so hot. The "lock" implementation is killer.

    I think the "easiest" thing, as you mentioned, would be to expire the cart/session after a user-selectable time... We'd have to look into that and make sure it wouldn't break anything else. Do you see this as a store-wide setting? If we're talking about a per-product expiration that definitely gets more complicated.

    How would you see an entire cart expiring in relation to your product-specific locks? If you load another item at minute 14, that'd extend the cart expiration out another 15 minutes, but would the product inside the cart get unlocked 1 minute in? Something to think about.
  • I think that it would be best if there was a store wide expire, i.e. kill the entire cart after the period of inactivity.

    And I don't think I would need product specific expirations for the cart. I'd say anything in their cart remains valid unless they haven't visited / refreshed any page on the site. So, if there is no activity on any of the site from their IP address for 15 minutes, they lose the entire cart. If they are idle for 14, but then click a new page, the entire cart is given a new fresh 15 minutes. So, I guess the entire cart gets a renewed 15 minutes (or whatever period of time is desired) every time the user visits any page on the site.

    Do you think that's doable?
  • brettbrett FoxyCart Team
    Yeah, we'll look into it and let you know. You should probably have a 14 minute js timer that alerts your customers their cart is about to expire, and explaining why. Like banks do before they log you out.

    We'll figure out how involved that'll be to roll out and let you know.
  • Beautiful! And the 14 minute timer is a golden idea. Thanks.
  • Any word on the cart expiring? I don't mean to be impatient, but I'm sure you know how it is...
Sign In or Register to comment.