From f5aece5f7a0d5c6b227f8d71b0cf4fc23034be1f Mon Sep 17 00:00:00 2001 From: Christophe LATOUR Date: Mon, 4 Dec 2017 11:21:34 +0100 Subject: [PATCH] overriding lastNondeOrdered --- app/Models/Cart.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index 9ceaae4..05f087e 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -151,6 +151,35 @@ class Cart extends BaseCart )); } + + public static function getMaxIdOrdered($id_customer) { + $max_id = parent::getMaxIdOrdered($id_customer); + if (!$max_id) { + $max_id = \Db::getInstance()->getValue(' + SELECT MAX(c.`id_cart`) + FROM '._DB_PREFIX_.'cart c + WHERE c.`id_customer` = '.(int)$id_customer.' + '); + } + return $max_id; + } + + public static function lastNoneOrderedCart($id_customer) + { + if (($max_id_cart = self::getMaxIdOrdered($id_customer))) { + $id_cart = \Db::getInstance()->getValue(' + SELECT MIN(c.id_cart) + FROM '._DB_PREFIX_.'cart c + LEFT JOIN '._DB_PREFIX_.'orders o ON (c.`id_cart` = o.`id_cart`) + WHERE o.`id_order` IS NULL + AND c.`id_customer` = '.(int)$id_customer.' + AND c.`id_cart` >= '.(int)$max_id_cart.' + '); + return $id_cart ? $id_cart : false; + } + return false; + } + public function apiGetAvailableCarriers(Request $request) { $customer = $request->user(); $address = new ApiAddress((int)($this->id_address_delivery));