* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ namespace PrestaShop\Module\PrestashopCheckout\Repository; /** * Class OrderRepository used to interact with the DB order table */ class OrderRepository { /** * Get last 1000 pending checkout orders * * @param int $shopId * @param array $idStates * * @return array|bool|\mysqli_result|\PDOStatement|resource * * @throws \PrestaShopDatabaseException */ public function findByStates($shopId, array $idStates) { $orders = \Db::getInstance()->executeS(' SELECT o.id_order, o.id_currency, o.current_state, o.total_paid, o.date_add, c.id_customer, c.firstname, c.lastname FROM `' . _DB_PREFIX_ . 'orders` o INNER JOIN `' . _DB_PREFIX_ . 'customer` c ON (o.id_customer = c.id_customer) WHERE o.module = "ps_checkout" AND o.id_shop = ' . (int) $shopId . ' AND o.current_state IN (' . implode(', ', array_map('intval', $idStates)) . ') ORDER BY o.date_add DESC LIMIT 1000 '); if (empty($orders)) { return []; } return $orders; } /** * Returns total orders * * @param int $shopId * * @return int */ public function count($shopId) { return (int) \Db::getInstance()->getValue(' SELECT COUNT(id_order) FROM `' . _DB_PREFIX_ . 'orders` WHERE module = "ps_checkout" AND id_shop = ' . (int) $shopId ); } }