Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Keep Session Alive

    Hello All,
    Still working on 1.5.8a w/PHP 8.2.4. I have achieved a session keep alive which works fine, but has one major issue. lol

    So I'm activating the function by:
    $(document).ready(function(){
    timerKeepAlive();
    });

    The function:
    function timerKeepAlive() {
    setInterval(function() {
    $.ajax({url: location});
    }, 300000); //five minutes
    }

    On a PC this works forever as long as the browser isn't closed. On a mobile it works forever while browsing other tabs. However, when I hit the power button to (for lack of a better term) 'rest/sleep' the phone, the session dies and I come back to an empty cart.

    How can I get a visitor's cart to survive a sleeping cellphone?

    Thank you,
    John

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,509
    Plugin Contributions
    88

    Default Re: Keep Session Alive

    Quote Originally Posted by bumba000 View Post
    Hello All,
    Still working on 1.5.8a w/PHP 8.2.4. I have achieved a session keep alive which works fine, but has one major issue. lol

    So I'm activating the function by:
    $(document).ready(function(){
    timerKeepAlive();
    });

    The function:
    function timerKeepAlive() {
    setInterval(function() {
    $.ajax({url: location});
    }, 300000); //five minutes
    }

    On a PC this works forever as long as the browser isn't closed. On a mobile it works forever while browsing other tabs. However, when I hit the power button to (for lack of a better term) 'rest/sleep' the phone, the session dies and I come back to an empty cart.

    How can I get a visitor's cart to survive a sleeping cellphone?

    Thank you,
    John
    Keep Cart: https://www.zen-cart.com/downloads.php?do=file&id=992

  3. #3
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Re: Keep Session Alive

    Quote Originally Posted by lat9 View Post
    That's insane. Thank you lat9.

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

    Default Re: Keep Session Alive

    Quote Originally Posted by bumba000 View Post
    Hello All,
    Still working on 1.5.8a w/PHP 8.2.4. I have achieved a session keep alive which works fine, but has one major issue. lol

    So I'm activating the function by:
    $(document).ready(function(){
    timerKeepAlive();
    });

    The function:
    function timerKeepAlive() {
    setInterval(function() {
    $.ajax({url: location});
    }, 300000); //five minutes
    }

    On a PC this works forever as long as the browser isn't closed. On a mobile it works forever while browsing other tabs. However, when I hit the power button to (for lack of a better term) 'rest/sleep' the phone, the session dies and I come back to an empty cart.

    How can I get a visitor's cart to survive a sleeping cellphone?

    Thank you,
    John
    Can also force login. Items in the cart of a logged in customer, generally stay with the customer.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Re: Keep Session Alive

    Quote Originally Posted by mc12345678 View Post
    Can also force login. Items in the cart of a logged in customer, generally stay with the customer.
    Yeah I know I just don't want to force a visitor to create an account. Thanks tho.

  6. #6
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Re: Keep Session Alive

    Quote Originally Posted by lat9 View Post
    Hey Lat9. Any idea why keep cart wont let the customer empty the cart? I haven't tried logging in, but a visitor creates a cart and all but the last item can be deleted from the cart. I disable the plugin and I can delete the last item in cart.

    1.5.8a on 8.4.2

    Thanks again,
    John

  7. #7
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Re: Keep Session Alive

    I'm pretty sure I have this ironed out. In the file includes/classes/class.savecart.php

    Just inside of the folliwing statment
    if (isset($_COOKIE['cart'], $_COOKIE['cartkey']) && isset($_SESSION['cart']) && empty($_SESSION['cart']->contents)) {

    I added...
    if($_SESSION['cart']->count_contents() === 0){
    $this->expireKeepCartCookie();
    return;
    }

    Seems to be working. I'll post back if I find that my solution is causing a problem. If you come up with a better solution please let me know before this goes live. ;)

    Thanks again,
    John

  8. #8
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Re: Keep Session Alive

    Nope. That's not working. Doesn't restore the cart once the php session expires.

  9. #9
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Re: Keep Session Alive

    It's funny i guess that I thought my above listed solution might work. Asking if the cart's empty inside of an if cart empty ? lol. Well I still haven't quite found a solution, but I realize that there's a few things firing off before getting to the class.savecart file. So the cart does actually become empty after the classes/shopping_cart.php ->remove function is run. I am in that remove function trying to unset the cookie, but I just haven't nailed it down. Am I at least on the right path here?

    Thanks again,
    John

    PS. Just to recap.
    ZC 1.5.8 on PHP 8.4.2.
    ZC session time (for testing) = 120 sec
    Cookie life = 30 days
    Add items to cart, close browser come back an hour later everything's there.
    Deleting items from shopping cart works until the very last item. The last item can not be removed from cart.

  10. #10
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    806
    Plugin Contributions
    0

    Default Re: Keep Session Alive

    Another failed attempt...
    Inside the remove function of classes/shopping_cart.php just before the closing curly of the function I added the following...

    if(empty($_SESSION['cart']->contents)){
    $_SESSION['cookieremover'] = 'remove';
    }


    Then in the class.savecart.php file I changed

    if ($cart_contents === false) {
    $this->expireKeepCartCookie();
    return;
    }

    to this

    if ($cart_contents === false || (isset($_SESSION['cookieremover']) && $_SESSION['cookieremover'] == 'remove')) {
    $_SESSION['cookieremover'] = '';
    $this->expireKeepCartCookie();
    return;
    }


    So with this in place, I add an item to the cart then delete the item. It does get removed from cart, but on next page load the item is restored. I guess a week is long enough. I'll fool around with it a little more today, but ultimately I feel i'm gonna have to pull the plug on this plugin until a solution is found.

    Thanks again for all the help.

    Best,
    John

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Can I keep session when browser close?
    By linjuming in forum General Questions
    Replies: 0
    Last Post: 5 Sep 2012, 10:53 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR