Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Plugin Contributions
    0

    Default Add to cart button sometimes doesn't work

    My problem is, that sometimes if I click on the Add_to_cart button it redirects me to the cart but doesn't add the item to it. This problem can not be reproduced however it happens more often if I press the button really fast (before page load finished). Maybe it happens on slower pc-s more often, but I can reproduce it at least once in 10 add_to_cart actions.
    I haven't found the solution in the forum so I've searched it myself and now I write it down, if anybody suffers from the same problem.

    So after I click the button the product is added to the shopping_cart in the session and the zen_redirect function in functions_general.php redirects me to the shopping cart. But somehow the session has not enough time to be saved before the call of the redirect function (named header).
    If I debug it, I can see that the product is added to the cart before the call of the header, but it is missing from the cart after the session is started on the shopping_cart page.
    This session behavior is a known malfunction in php.

    I can solve the problem if I put session_regenerate_id(true); before the call of the header function in zen_redirect(). At least it solved the problem for me...

    eastwood

  2. #2
    Join Date
    Jul 2006
    Location
    Poland
    Posts
    31
    Plugin Contributions
    0

    Default Re: Add to cart button sometimes doesn't work

    I have got a same problem with my zen cart installation. Could You describe with more details what and where do I have to change?

    TIA

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

    Default Re: Add to cart button sometimes doesn't work

    Gee ... if I hit the add to cart as fast as I can I can get 10 added to the cart before the page changes to the cart ...

    Don't do that ...

    If someone is going to sit there and hit a button as fast as they can, what do they expect to happen?

    NOTE: I cannot get that to *not* add at least 1 to the cart when I hit the add to cart multiple times ...
    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!

  4. #4
    Join Date
    Oct 2009
    Posts
    2
    Plugin Contributions
    0

    Default Re: Add to cart button sometimes doesn't work

    Don't hit the add_to_cart button multiple times. Just hit it once.
    Imagine a fast customer who knows you webshop very well and wants to buy for example 10 different products. So this customer will navigate through your site and drop the products in the cart really fast. He will not wait for finishing the page load as soon as he notice the add_to_cart button he will click it (once). And he will be redirected to the shopping cart always but sometimes the selected product will not be there.

    And this behavior is because php sometimes doesn't save the session when it use the header function to redirect. Maybe it has no time for it and maybe itt happens on overloaded servers more often, I don't know. The fact is that I could reproduce this problem both on my pc (php 5.2.3) and on the server (php 5.2.8) where my webshop runs.

    All in all it is a known php problem (google for it) and you can solve it by calling the session_regenerate_id() function before the call of the header() function.

    More precisely: search for zen_redirect() in ../includes/functions/functions_general.php and make the modification below.

    Code:
    function zen_redirect($url) {
        global $request_type;
        // Are we loading an SSL page?
        if ( (ENABLE_SSL == true) && ($request_type == 'SSL') ) {
          // yes, but a NONSSL url was supplied
          if (substr($url, 0, strlen(HTTP_SERVER . DIR_WS_CATALOG)) == HTTP_SERVER . DIR_WS_CATALOG) {
            // So, change it to SSL, based on site's configuration for SSL
            $url = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . substr($url, strlen(HTTP_SERVER . DIR_WS_CATALOG));
          }
        }
    
      // clean up URL before executing it
        while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);
        while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);
        // header locates should not have the & in the address it breaks things
        while (strstr($url, '&')) $url = str_replace('&', '&', $url);
    
        session_regenerate_id(true);
        header('Location: ' . $url);
    
        zen_exit();
      }

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

    Default Re: Add to cart button sometimes doesn't work

    Thanks for the update ... we will look into this further to see what we can break ... er ... fix ...

    Now where are those smart boys hiding ...
    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!

 

 

Similar Threads

  1. Add to cart link doesn't work
    By panuma in forum General Questions
    Replies: 6
    Last Post: 30 Nov 2010, 07:46 PM
  2. sometimes ie8 add to cart doesn't work on my site
    By Maxie1971 in forum Bug Reports
    Replies: 36
    Last Post: 21 Apr 2010, 01:14 PM
  3. Preview button doesn't work - can't add products
    By dsided in forum Installing on a Linux/Unix Server
    Replies: 16
    Last Post: 8 Oct 2009, 06:26 PM
  4. Add to cart button doesn't add - from any page
    By jguttman in forum General Questions
    Replies: 23
    Last Post: 3 Oct 2009, 03:12 PM
  5. Sporadic - Add to Cart Button doesn't Add
    By jromanoff in forum Bug Reports
    Replies: 11
    Last Post: 6 Aug 2006, 07:15 AM

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