"Expiration" of Shopping Cart Items??

greenspun.com : LUSENET : S-Mart Shopping Cart : One Thread

I'm setting up the S-Mart shopping cart on a test site. My question is: When or how does one's shopping cart expire? That is, upon testing the shopping cart, I put a few items in the cart then do not process the order. I clear my caches and then return to the test site only to see that my unprocessed cart items are still there. I have verified this "lingering cart" on some commerical sites that are up and running. If customers using this script put some items in their cart, then leave the site and return the next day, will there items still be there? One would hope not. Right now the only way I can delete items and get back to an empty cart is by manually removing all quantities of shopping-cart items and then recalculating.

Please advise on how or if I can configure the script to "clear unprocessed carts." Many thanks for any help!

Randy Scott

-- Randy Scott (randy@obatadesign.com), December 19, 1997


Hi Randy,

This seems to be a very real problem and Im glad someone else has found it as well.......read my other posts regarding this also.

Im not sure if you have tested the problem by actually logging off and then back on again (you should try that). The cart is kept on your server until the order is completed.....the filename of the cart has your current IP number attached to it and is stored on the server....not in your cache, so clearing the cache will not clear the cart. The cart is only deleted if an order is actually processed. If you do not log off and hence have the same IP number then the cart will stay there indefinitely......this is not a big problem (unless someone happens to log in with the same IP that you were using) but there is another problem associated with this, I have found that when I log in through a certain ISP that I use then I will receive the previous order that I made (but didnt complete) even after I have logged back in again under a new IP number..........but this only happens with some ISP's, not all, as I have tested with an alternate provider and it works fine.

I have been talking to a guy about how to get around this by setting up a script to delete the cart files in the tmp dir once every day......and also to check to see if the cart is over a certain age and if so then ignore it.

Trouble is he hasnt got back to me yet........send me an EMail this week before Wednesday and I'll let you know if I got the info I needed. Dont forget to read my other posts here.



-- Graham Jupp (gjupp@bayweb.com.au), December 20, 1997.

This isn't a problem. It's the way it's designed. Carts are kept in the temp directory till they are deleted. If you use /tmp, then this will be done by the system, otherwise, just make a cronjob that deletes the files every so often.

crontab -e

than add

0 0 * * 0,2,4 rm /tempdirectory/storename-*

-- Barry Robison (brobison@rcinet.com), December 20, 1997.

I solved the problem like this....

In the get_host sub, I added a .cart extension to the cart names. Then I added a sub to remove old carts. Using grep, I found all files(carts) that had a .cart extension and used the -M test to check for the cart age. If it was older than half a day, delete it.

Here is the source for the changes needed to get_host(), the new sub remove_old_carts() and how to call remove_old_carts(). Search for &get_host; and replace it with this code snippet:

## replace call to &get_host; with this... ############
if ($reffile eq "")

#### changes to get_host() ######### sub get_host { $host = $ENV{'REMOTE_HOST'}; $reffile = "$tmpdir$delim-$host.cart"; }

#### new sub remove_old_carts ########## sub remove_old_carts { opendir (USER_CARTS, "$tmpdir") || &Error("$tmpdir"); @carts = grep(/\.cart/,readdir(USER_CARTS)); closedir (USER_CARTS);

foreach $cart (@carts) { # how many days to keep old carts # .5 == 1/2 day

if (-M "$tmpdir/$cart" > '.5') { unlink("$tmpdir/$cart"); } } } # End of sub remove_old_carts

-- Tom (tom@haddonfield.com), December 21, 1997.

This seems to work! find /usr/???/smart/tmp -atime +1 -exec rm {} \;

-- Bo (bo_ski@nightmail.com), December 18, 1998.

Moderation questions? read the FAQ