Jump to content

Combining shopping cart when guest logs in


mark2

Recommended Posts

Hi,

If a user:

logs in, adds some items to their shopping cart, logs out. Then as a guest adds items to a shopping cart, then logs in.

The first shopping cart is lost. I wanted the two carts to be combined. It seems this can be done in the authentication.php file:

            
if (Configuration::get('PS_CART_FOLLOWING')){
 if (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0) {
   $cookie->id_cart = intval(Cart::lastNoneOrderedCart(intval($customer->id)));
 } else {
   // Combine orders
   $lastCartID = Cart::lastNoneOrderedCart(intval($customer->id));
   if (Cart::getNbProducts($cookie->id_cart) > 0 && $lastCartID) {
      $last_cart = new Cart($lastCartID);
      if (!Validate::isLoadedObject($last_cart)) {
        $products = $cart->getProducts();
        foreach ($products as $p) {
          $last_cart->updateQty($p['cart_quantity'], $p['id_product']);
        }
        $last_cart->update();
        $cart->delete();
        $cart = $last_cart;
        $cookie->id_cart = $cart->id;
      }
    }
 }
}



This might be of use to someone. Or you might see a problem with this, in which case your comments would be of use to me.

Regards,
Mark

Link to comment
Share on other sites

  • 8 months later...

Hi, the code did not work for customized products but seemed OK otherwise. I'm using 1.2.5 so the code may not work on any other version. I hacked something together to deal with customized products you can PM me about that.

Link to comment
Share on other sites

  • 5 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...