diff --git a/classes/Cart.php b/classes/Cart.php index f3f10f888..9e8edcee4 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -2991,14 +2991,14 @@ class CartCore extends ObjectModel return $result; } - public static function getCustomerCarts($id_customer) + public static function getCustomerCarts($id_customer, $with_order = true) { - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' - SELECT * - FROM '._DB_PREFIX_.'cart c - WHERE c.`id_customer` = '.(int)$id_customer.' - ORDER BY c.`date_add` DESC'); - return $result; + return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + SELECT * + FROM '._DB_PREFIX_.'cart c + WHERE c.`id_customer` = '.(int)$id_customer.' + '.(!$with_order ? 'AND id_cart NOT IN (SELECT id_cart FROM '._DB_PREFIX_.'orders o WHERE o.`id_customer` = '.(int)$id_customer.')' : '').' + ORDER BY c.`date_add` DESC'); } public static function replaceZeroByShopName($echo, $tr) diff --git a/classes/Customer.php b/classes/Customer.php index 729665803..a5c4e3930 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -737,9 +737,9 @@ class CustomerCore extends ObjectModel $this->logged = 0; } - public function getLastCart() + public function getLastCart($with_order = true) { - $carts = Cart::getCustomerCarts((int)$this->id); + $carts = Cart::getCustomerCarts((int)$this->id, $with_order); if (!count($carts)) return false; $cart = array_shift($carts); diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 3fe25d9c4..f51ded177 100755 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -188,7 +188,7 @@ class AdminCartsControllerCore extends AdminController $this->context->customer = $customer; $id_cart = (int)Tools::getValue('id_cart'); if (!$id_cart) - $id_cart = $customer->getLastCart(); + $id_cart = $customer->getLastCart(false); $this->context->cart = new Cart((int)$id_cart); if (!$this->context->cart->id_customer) $this->context->cart->id_customer = $id_customer;