1
votes

I'd like to be able to set a time span that a customers' cart would expire, so once an item is added to their cart, they have say 15 minutes to checkout before all items are removed from cart and stock numbers are replenished on the these particular items.

This works by changing the Cookie Session time in the configuration for Magento, but with the unintended side effects of logging the user (and admin) out. Is there a way to just set the "session" time of the cart and not the user?

1
Cookie Session will not help you as logged off user still have his items in cart.user487772
Actually, timing out the session cookie WILL help, because the basket is stored in session variables. An expired session means the $_SESSION array is destroyed. On the downside, it'll log you out too.Polynomial

1 Answers

0
votes

If Magento has a common include file (it most likely will, since it's based on Zend) you can add an entry to $_SESSION to specify the time of the last request. You can then compare it with the current time on new requests, and clear any basket-specific entries in the session if it's exceeded 15 minutes.

if(isset($_SESSION['_last_page_hit']))
{
    if(time() - (int)$_SESSION['_last_page_hit'] < (60*15))
    {
        unset($_SESSION['basket_whatever']); // unset basket stuff here
    }
}
$_SESSION['_last_page_hit'] = time();

You'll remain logged in, but any basket data will be removed. Obviously you'll need to find out what session variables need to be unset, so a few calls to var_dump() may be in order!