buhajus Posted April 9, 2018 Share Posted April 9, 2018 (edited) Good day, anyone can help me with ordering products by products reference in AdminOrder in this section? I found in classes/Order.php this function, but when i added ORDER BY... i got blank table of products. public function getProductsDetail() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT * FROM `'._DB_PREFIX_.'order_detail` od LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id) LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop) WHERE od.`id_order` = '.(int)$this->id.'ORDER BY od.product_reference ASC'); } Any ideas ? Edited April 9, 2018 by buhajus (see edit history) Link to comment Share on other sites More sharing options...
stupidcomputer Posted July 1, 2019 Share Posted July 1, 2019 public function getProductsDetail() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT * FROM `'._DB_PREFIX_.'order_detail` od LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id AND p.id_category_default) LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop AND ps.id_category_default = p.id_category_default) WHERE `id_order` = '.(int)$this->id.' ORDER BY ps.`id_category_default` ASC'); } I did this to sort the products based on the category ID, in ascending order. I think that to order them based on the reference code the code is more or less like this (sorry for my english): public function getProductsDetail() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT * FROM `'._DB_PREFIX_.'order_detail` od LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id AND p.reference) LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop) WHERE `id_order` = '.(int)$this->id.' ORDER BY p.`reference` ASC'); } Link to comment Share on other sites More sharing options...
stupidcomputer Posted July 1, 2019 Share Posted July 1, 2019 public function getProductsDetail() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT * FROM `'._DB_PREFIX_.'order_detail` od LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = od.product_id AND p.reference = od.product_reference) LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop) WHERE `id_order` = '.(int)$this->id.' ORDER BY od.`product_reference` ASC'); } Sorry, I made a mistake, now it should be correct. Link to comment Share on other sites More sharing options...
Mattisa Posted October 31, 2020 Share Posted October 31, 2020 Hello, Do you have a solution for Prestashop 1.7 ? I tried to do that, but it seems that it does not work for me. Thank you 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