lat9 / keep_cart

Keeps a Zen Cart "cart" in a browser cookie.
GNU General Public License v2.0
1 stars 1 forks source link

User always redirected to the timeout page because cartID is not set #1

Closed marco-pm closed 2 years ago

marco-pm commented 2 years ago

If the user has some items in cart and the session expires, then the user comes back and the cart contents are restored using the cookie, if he/she tries to checkout as a guest, the following check fails:

if (isset($_SESSION['cart']->cartID)) {
  if (!isset($_SESSION['cartID']) || $_SESSION['cart']->cartID != $_SESSION['cartID']) {
    $_SESSION['cartID'] = $_SESSION['cart']->cartID;
  }
} else {
  zen_redirect(zen_href_link(FILENAME_TIME_OUT));
}

thus he/she is always redirected to the timeout page.

In fact the cartID is not set by the observer class after restoring the cart contents, unlike e.g. the restore_contents() function of the shopping cart (called after a registered user logs in):

    $this->cartID = $this->generate_cart_id();
    $this->notify('NOTIFIER_CART_RESTORE_CONTENTS_END');
    $this->cleanup();

Adding this line in the constructor of the class.savecart.php, inside and at the end of the condition if ($hash_key === $_COOKIE['cartkey']) {, solved the issue for me:

$_SESSION['cart']->cartID = $_SESSION['cart']->generate_cart_id();
lat9 commented 2 years ago

@marco-pm, thanks (as always) for your notifications and insights.