WisQQ Posted March 31, 2021 Share Posted March 31, 2021 (edited) Hello, I would like to add 2 columns to orders listing to be able to sortby phone number or email. It worked before 1.7.7.0 by just simply adding them to override adminordercontroller.php. but after upgrade nothing works. I also tried to change these values with /src/PrestaShopBundle/Controller/Admin/Sell/Order but it didnt work. When i manually run query created through listing and add these 2 it showsup with no problems. SELECT CONCAT(LEFT(cu.`firstname`, 1), '. ', cu.`lastname`) AS `customer`, o.id_order, a.phone,cu.email, o.reference, o.total_paid_tax_incl, os.paid, osl.name AS osname, o.id_currency, cur.iso_code, o.current_state, o.id_customer, cu.`id_customer` IS NULL as `deleted_customer`, os.color, o.payment, s.name AS shop_name, o.date_add, cu.company, cl.name AS country_name, o.invoice_number, o.delivery_number, IF ((SELECT so.id_order FROM ps_orders so WHERE (so.id_customer = o.id_customer) AND (so.id_order < o.id_order) LIMIT 1) > 0, 0, 1) AS new FROM ps_orders o LEFT JOIN ps_customer cu ON o.id_customer = cu.id_customer LEFT JOIN ps_currency cur ON o.id_currency = cur.id_currency INNER JOIN ps_address a ON o.id_address_delivery = a.id_address LEFT JOIN ps_order_state os ON o.current_state = os.id_order_state LEFT JOIN ps_shop s ON o.id_shop = s.id_shop INNER JOIN ps_country c ON a.id_country = c.id_country INNER JOIN ps_country_lang cl ON c.id_country = cl.id_country AND cl.id_lang = 1 LEFT JOIN ps_order_state_lang osl ON os.id_order_state = osl.id_order_state AND osl.id_lang = 1 WHERE o.`id_shop` IN ('1') ORDER BY o.id_order DESC LIMIT 50 For now i went back to 1.7.6.9. Edited March 31, 2021 by WisQQ (see edit history) Link to comment Share on other sites More sharing options...
WisQQ Posted September 21, 2022 Author Share Posted September 21, 2022 Dnia 31.03.2021 o 10:21 AM, WisQQ napisał: Hello, I would like to add 2 columns to orders listing to be able to sortby phone number or email. It worked before 1.7.7.0 by just simply adding them to override adminordercontroller.php. but after upgrade nothing works. I also tried to change these values with /src/PrestaShopBundle/Controller/Admin/Sell/Order but it didnt work. When i manually run query created through listing and add these 2 it showsup with no problems. SELECT CONCAT(LEFT(cu.`firstname`, 1), '. ', cu.`lastname`) AS `customer`, o.id_order, a.phone,cu.email, o.reference, o.total_paid_tax_incl, os.paid, osl.name AS osname, o.id_currency, cur.iso_code, o.current_state, o.id_customer, cu.`id_customer` IS NULL as `deleted_customer`, os.color, o.payment, s.name AS shop_name, o.date_add, cu.company, cl.name AS country_name, o.invoice_number, o.delivery_number, IF ((SELECT so.id_order FROM ps_orders so WHERE (so.id_customer = o.id_customer) AND (so.id_order < o.id_order) LIMIT 1) > 0, 0, 1) AS new FROM ps_orders o LEFT JOIN ps_customer cu ON o.id_customer = cu.id_customer LEFT JOIN ps_currency cur ON o.id_currency = cur.id_currency INNER JOIN ps_address a ON o.id_address_delivery = a.id_address LEFT JOIN ps_order_state os ON o.current_state = os.id_order_state LEFT JOIN ps_shop s ON o.id_shop = s.id_shop INNER JOIN ps_country c ON a.id_country = c.id_country INNER JOIN ps_country_lang cl ON c.id_country = cl.id_country AND cl.id_lang = 1 LEFT JOIN ps_order_state_lang osl ON os.id_order_state = osl.id_order_state AND osl.id_lang = 1 WHERE o.`id_shop` IN ('1') ORDER BY o.id_order DESC LIMIT 50 For now i went back to 1.7.6.9. There are 2 solutions to this. One is to create module to add another column to the grid, second is to manually add it to the grid inside these files: src\Core\Grid\Definition\Factory\OrderGridDefinitionFactory.php protected function getColumns(){ $columns = (new ColumnCollection()) ->add((new IdentifierColumn('id_order')) ->setName($this->trans('ID', [], 'Admin.Global')) ->setOptions([ 'identifier_field' => 'id_order', 'preview' => $previewColumn, 'clickable' => false, ]) ) } src\Core\Grid\Query\OrderQueryBuilder.php private function getBaseQueryBuilder(array $filters) { $qb = $this->connection ->createQueryBuilder() ->from($this->dbPrefix . 'orders', 'o') ->leftJoin('o', $this->dbPrefix . 'customer', 'cu', 'o.id_customer = cu.id_customer') ->leftJoin('o', $this->dbPrefix . 'order_carrier', 'oc', 'o.id_carrier = oc.id_carrier') ->leftJoin('o', $this->dbPrefix . 'currency', 'cur', 'o.id_currency = cur.id_currency') public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria) { $qb = $this ->getBaseQueryBuilder($searchCriteria->getFilters()) ->addSelect($this->getCustomerField() . ' AS `customer`') Link to comment Share on other sites More sharing options...
ps8modules.com Posted September 21, 2022 Share Posted September 21, 2022 (edited) Hi. Just write the names of the columns and in which database table they are located. When I have all the information, I will give you sample code in your module. hooks: actionOrderGridDefinitionModifier, actionOrderGridDataModifier, actionOrderGridQueryBuilderModifier, actionAdminOrdersListingFieldsModifier, actionAdminOrdersListingResultsModifier Edited September 21, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
WisQQ Posted September 22, 2022 Author Share Posted September 22, 2022 11 godzin temu, 4you.software napisał: Hi. Just write the names of the columns and in which database table they are located. When I have all the information, I will give you sample code in your module. hooks: actionOrderGridDefinitionModifier, actionOrderGridDataModifier, actionOrderGridQueryBuilderModifier, actionAdminOrdersListingFieldsModifier, actionAdminOrdersListingResultsModifier hi, u can paste example module here. I'll adjust it for my purpose. I just wanted to share information where to find it. Link to comment Share on other sites More sharing options...
ps8modules.com Posted September 22, 2022 Share Posted September 22, 2022 https://devdocs.prestashop-project.org/1.7/development/components/grid/tutorials/modify-grid-in-module/ Link to comment Share on other sites More sharing options...
ps8modules.com Posted September 22, 2022 Share Posted September 22, 2022 Changing anything in the src folder is not a good way when there are hooks and functions. Link to comment Share on other sites More sharing options...
WisQQ Posted September 22, 2022 Author Share Posted September 22, 2022 (edited) I understand that its not a good way, but sometimes adding 2 lines of code is all what u need I would say it's more like "right here, right now solution" and if u need something more future proof then proceed to develop module. Edited September 22, 2022 by WisQQ (see edit history) Link to comment Share on other sites More sharing options...
ps8modules.com Posted September 22, 2022 Share Posted September 22, 2022 And when the upgrade is done, the override in src will be gone, while the hooks in the module will be functional. 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