I know I need to putin the logoff file, but when I do, the cart contents remain after logging back in.Code:$_SESSION['cart']->reset(true);
I know I need to putin the logoff file, but when I do, the cart contents remain after logging back in.Code:$_SESSION['cart']->reset(true);
I'm not sure what "the logoff file" is, but if you edit /includes/modules/pages/logoff/header_php.php (a core-file, so make sure you have a backup) as follows, that should do the trick.Code:<?php /** * logoff header_php.php * * @package page * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: header_php.php 5403 2006-12-27 00:38:58Z drbyte $ */ // This should be first line of the script: $zco_notifier->notify('NOTIFY_HEADER_START_LOGOFF'); require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php')); $breadcrumb->add(NAVBAR_TITLE); /** * Check what language should be used on the logoff screen */ $logoff_lang = ($_SESSION['languages_code'] != DEFAULT_LANGUAGE) ? 'language=' . $_SESSION['languages_code'] : ''; /** * Clear the customer's cart */ $_SESSION['cart']->reset(true); /** * Check if there is still a customer_id * If so, kill the session, and redirect back to the logoff page * This will cause the header logic to see that the customer_id is gone, and thus not display another logoff link */ if (!empty($_SESSION['customer_id']) || !empty($_SESSION['customer_guest_id'])) { zen_session_destroy(); zen_redirect(zen_href_link(FILENAME_LOGOFF, $logoff_lang)); } // This should be last line of the script: $zco_notifier->notify('NOTIFY_HEADER_END_LOGOFF'); ?>
This is just what I needed, thank you! However, if I'm not mistaken, this only takes place if the customer actually uses the Log Off button. Somewhere in the code (I have not been able to find it) I expect there must be some code to clear a session if the customer just shuts down the browser or goes to another site without physically logging off. If some one could direct me to that file I would like to add the same code so that a customer cannot hold items in their shopping cart. Basically, this site has limited numbers of items and it is supposed to be first to pay is the one that gets the item, but if someone adds an item that there is only one of, it is taken out of inventory and essentially "reserved" until the customer either pays for the item or clears their cart. I need to make it so the shopping cart does not persist if the customer is not active on the site.
Mal
P.S. I hope resurrecting an old post like this is not frowned upon. This post is exactly what I was looking for so I responded.
No problem in posting to an older potentially related post.
Have to ask though, based on the information above, is it first to purchase or first to add to the cart? Fom the description of the current functionality it is first to add to cart gets "dibs". If that is is the case "first to add to cart" then this thread and the question about returning items to the cart are needed. (Basically disable the storage functionality for logged in customers.) If it is intended to be only first to purchase, then a different modification to the cart is necessary to subtract the inventory at a different point.
One thought experiment to consider about how the current site is setup based upon the above, if a bot were to come through and add every item to a cart, wouldn't everything be unavailable? And all it would need to do after that is to navigate to another page every few minutes to keep the session alive and hold all of the items with no sale being made...
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
Let's make sure you really need this ...
Bots cannot login and complete orders
While it can be obnoxious that bots "fill" a cart, the Products in the cart are still available to anyone as nothing is removed from stock until an Order is "completed". So, since bots cannot complete an order, nothing is removed from stock by a bot.
As a customer, it would be aggravating to me if I am going through a store and putting all kinds of things in my shopping cart then getting a phone call or having to fold the laundry only to return to my computer to find out not only is my shopping cart empty, despite having been logged in, but if I login again, my shopping cart is still empty! I would have to pack up my credit card and go shop elsewhere ...
What do you think will be accomplished by this? If it is just because you thought your stock was being reduced by things added to the cart, then never fear you do not have to worry ...
First to checkout with the Product is the winner!![]()
Linda McGrath
If you have to think ... you haven't been zenned ...
Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!
Interesting. I could have sworn that an item was removed from inventory when added to a cart, and was (if my memory serves me correctly) told as much in another thread. If it really is not removed from stock until paid for, then I guess the women will just have to fight it out. The owner was getting messages from upset customers that things were being "stolen" out of their carts. I guess it's just that they took too long deciding and someone else checked out first.
Mal
Things would only be "taken" from the cart if multiple people put the same Product in the cart and one of them finishes a checkout ...
That checkout by the first customer to checkout will remove the Product from stock and now it can be removed from anyone who is still shopping as now it is no longer available ...
Linda McGrath
If you have to think ... you haven't been zenned ...
Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!
So, a couple of things and glad that you got back to this thread... If the individual is not logged in, and they venture away long enough for the session to expire then yes when they begin to navigate around again, the previous items in the cart would have been stolen away, otherwise all that ajeh was saying above is standard zencart behavior such that if the individual were logged in when the item(s) were added to the cart, then once they are purchased by someone else, then yes they will get stolen from them when they *do* goto the shopping cart... I had found another thread yesterday (possibly at the bottom of this page) that described the general wording and conditions one could expect related to all of this. So looks like if you applied the above code modification that you may want to undo it...
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
Quite so, you are correct that I should undo it, and once I saw ajeh's post, I did so.I also explained to the owner how it worked and she was sad that someone making a large purchase could lose items they had added to their cart to someone possibly purchasing only that one item, but I paraphrased a response "He/She who checks out first wins" and she understood and can now explain what really happened to the unhappy customers. It won't make them any more happy, but she has ways of making unhappy customers happy. Thank you all for your input and explanations as every single one helped me get to a point where I could truely say it wasn't anything I did, it is just the way things work.
Mal