Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Feb 2012
    Posts
    67
    Plugin Contributions
    0

    Default Remove cart contents after logging out

    I know I need to put
    Code:
    $_SESSION['cart']->reset(true);
    in the logoff file, but when I do, the cart contents remain after logging back in.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,977
    Plugin Contributions
    96

    Default Re: Remove cart contents after logging out

    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');
    ?>

  3. #3
    Join Date
    Dec 2013
    Location
    Maine
    Posts
    77
    Plugin Contributions
    0

    Default Re: Remove cart contents after logging out

    Quote Originally Posted by lat9 View Post
    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.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Remove cart contents after logging out

    Quote Originally Posted by Malaperth View Post
    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...

  5. #5
    Join Date
    Dec 2013
    Location
    Maine
    Posts
    77
    Plugin Contributions
    0

    Default Re: Remove cart contents after logging out

    Quote Originally Posted by mc12345678 View Post
    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...

    The intention is first to purchase. And as far as the bot goes, due to my lack of knowledge of PHP, it would completely cripple the site as you pointed out, and I would have no idea how to programmatically keep it from happening a second time.

    Mal

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Remove cart contents after logging out

    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!

  7. #7
    Join Date
    Dec 2013
    Location
    Maine
    Posts
    77
    Plugin Contributions
    0

    Default Re: Remove cart contents after logging out

    Quote Originally Posted by Ajeh View Post
    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!
    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

  8. #8
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Remove cart contents after logging out

    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!

  9. #9
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Remove cart contents after logging out

    Quote Originally Posted by Malaperth View Post
    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
    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...

  10. #10
    Join Date
    Dec 2013
    Location
    Maine
    Posts
    77
    Plugin Contributions
    0

    Default Re: Remove cart contents after logging out

    Quote Originally Posted by mc12345678 View Post
    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...
    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

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Logging in twice - only after logging out
    By SarahL in forum Bug Reports
    Replies: 4
    Last Post: 1 Nov 2013, 07:53 PM
  2. Replies: 6
    Last Post: 27 Apr 2009, 10:28 PM
  3. Items disappearing from shopping cart after logging out.
    By crawlina in forum General Questions
    Replies: 1
    Last Post: 28 Jan 2009, 10:13 PM
  4. automatically kicks out the custome after logging in
    By orhonch in forum General Questions
    Replies: 1
    Last Post: 29 Feb 2008, 01:33 AM
  5. Some products disappear from cart when logging out
    By magicpants in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 18 Oct 2007, 09:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg