0
votes

I am working on a shopping cart in Perl. My client wants a product to become unavailable to others as soon as a customer adds it to his cart. If a user closes the browser without completing the order then the products should become available again.

Is it possible to access session values of all the online clients from the server in Perl, or is there another way I can make products available again if a person closes the browser without placing the order.

I don't want to use popup on window close as they are generally blocked by the users.

2
The language is called Perl, the binary file you execute to run Perl is called perl, there is no such thing as PERL.Quentin

2 Answers

1
votes

Is it possible to access Session values of all the online clients from the server

Yes. What that way is will depend on the session library you are using, but it is certainly possible.

It would be simpler to mark items as reserved in your main database when you add them to someone's cart though. Session data is for data private to the user, not for global data.

is there a way through which if a person closes the browser without making order

There is no way to reliably detect if the browser has been closed. Even if it has, then the user might have another window on the same site which isn't closed.

The usual basic approach to solving this is to reserve the item for a certain amount of time when it is added to the basket. You can tell the user how much time they have. This is an approach commonly used by theatres with reserved seating.

Your seats will be reserved for 20 minutes. If you do not complete your order in that time, they may be released and someone else may reserve them.

A slightly more complex approach would be to extend the reservation time whenever the user (identified by the session) interacts with the site. You might want to do this if people are browsing the site and buying multiple items.

You can clean up old reservations (which have expired) using a cron job.

0
votes

You could have javascript display an alert box when there are items in their shopping cart telling them that the product they have in the shopping cart may be lost to other users.

Assuming it is the last item and they press okay, you can create a function that submits whatever information you want to the server telling it that the user relinquished the item(s) in the shopping cart.