adlmr Posted November 26, 2022 Share Posted November 26, 2022 Hi all, I didn't use PrestaShop for a long time (last time was in 2014) 😁 I need to sort products in the order view (/index.php/sell/orders/1/view) by product reference. I checked on the forum and found a topic similar to my issue: so in Order.php > getProductsDetail() method, line 578, i updated WHERE od.`id_order` = ' . (int) $this->id); to WHERE od.`id_order` = ' . (int) $this->id . ' ORDER BY od.`product_reference` ASC'); but this doesn't work, products are not ordered by product_reference 😭 Link to comment Share on other sites More sharing options...
adlmr Posted December 10, 2022 Author Share Posted December 10, 2022 Answering to myself: using ORDER BY `p`.`reference` ASC doesn't work. Products are still ordered by `id_order_detail` Link to comment Share on other sites More sharing options...
adlmr Posted December 10, 2022 Author Share Posted December 10, 2022 (edited) 2 hours ago, adlmr said: Products are still ordered by `id_order_detail` This statement was false. After 2 hours on this problem, i found products array is sorted by key using ksort (https://www.php.net/manual/en/function.ksort.php) ksort($products); in src/Adapter/Order/QueryHandler/GetOrderProductsForViewingHandler.php, line 172. I commented this line and products are now sorted by reference (it is still necessary to make the SQL modification I gave on 1st post) Edited December 10, 2022 by adlmr (see edit history) Link to comment Share on other sites More sharing options...
Mattisa Posted June 29, 2023 Share Posted June 29, 2023 Pour trier les articles par référence, j'ai modifié la fonction getProducts du fichier AdminOrdersController.php (dans le dossier : controllers/admin/. Cette fonction se situe vers la ligne 2814 (dans mon cas). Voici à quoi ma fonction ressemble : protected function getProducts($order) { $products = $order->getProducts(); usort($products, function($a, $b) { return strcmp($a['reference'], $b['reference']); }); foreach ($products as &$product) { if ($product['image'] != null) { $name = 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg'; // generate image cache, only for back office $product['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $product['image']->getExistingImgPath() . '.jpg', $name, 45, 'jpg'); if (file_exists(_PS_TMP_IMG_DIR_ . $name)) { $product['image_size'] = getimagesize(_PS_TMP_IMG_DIR_ . $name); } else { $product['image_size'] = false; } } } ksort($products); return $products; } Après quoi vos articles seront triés par référence en ascendant. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now