BrahmsFun Posted December 31, 2020 Share Posted December 31, 2020 Hello I'm trying to display the customer group in the order list, which i actually did through the admin order controller file, but i'm having another issue: The customer group displayed is one of the defaluts and i want it to be a group i created instead (even showing both would be fine, i just need the non defalut one also showing). here's the lines responsable for displaying the customer group in the order list: $this->_select = ' CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`, \' (\', gr.`name`, \')\') AS `customer`, $this->_join = ' LEFT JOIN `' . _DB_PREFIX_ . 'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`id_lang`= '.(int)$this->context->language->id.') Maybe a condition that displays the higher id_group would be enough, but unfortunately i'm not that much familiar with PHP\SQL... Could anybody help ? ( PS version is 1.7.5.2 in case it's relevant) Thank you Link to comment Share on other sites More sharing options...
Alexandre Carette Posted December 31, 2020 Share Posted December 31, 2020 Hi you should use callback Link to comment Share on other sites More sharing options...
Alexandre Carette Posted December 31, 2020 Share Posted December 31, 2020 Link to comment Share on other sites More sharing options...
Alexandre Carette Posted December 31, 2020 Share Posted December 31, 2020 (edited) I created a new function call getAllGroups, cheers You should do an override of AdminOrdersController.php <?php /** * 2007-2018 PrestaShop. * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2018 PrestaShop SA * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ /** * @property Order $object */ class AdminOrdersController extends AdminOrdersControllerCore { public function __construct() { $this->bootstrap = true; $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); $this->explicitSelect = true; $this->allow_export = true; $this->deleted = false; parent::__construct(); $this->_select = ' a.id_currency, c.id_customer, a.id_order AS id_pdf, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, osl.`name` AS `osname`, os.`color`, IF((SELECT so.id_order FROM `' . _DB_PREFIX_ . 'orders` so WHERE so.id_customer = a.id_customer AND so.id_order < a.id_order LIMIT 1) > 0, 0, 1) as new, country_lang.name as cname, IF(a.valid, 1, 0) badge_success'; $this->_join = ' LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`) INNER JOIN `' . _DB_PREFIX_ . 'address` address ON address.id_address = a.id_address_delivery INNER JOIN `' . _DB_PREFIX_ . 'country` country ON address.id_country = country.id_country INNER JOIN `' . _DB_PREFIX_ . 'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = ' . (int) $this->context->language->id . ') LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON (os.`id_order_state` = a.`current_state`) LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) $this->context->language->id . ')'; $this->_orderBy = 'id_order'; $this->_orderWay = 'DESC'; $this->_use_found_rows = true; $statuses = OrderState::getOrderStates((int) $this->context->language->id); foreach ($statuses as $status) { $this->statuses_array[$status['id_order_state']] = $status['name']; } $this->fields_list = array( 'id_order' => array( 'title' => $this->trans('ID', array(), 'Admin.Global'), 'align' => 'text-center', 'class' => 'fixed-width-xs', ), /*Modif*/ 'id_customer' => array( 'title' => $this->trans('Groups', array(), 'Admin.Global'), 'callback' => 'getAllGroups', ), /*Modif*/ 'reference' => array( 'title' => $this->trans('Reference', array(), 'Admin.Global'), ), 'new' => array( 'title' => $this->trans('New client', array(), 'Admin.Orderscustomers.Feature'), 'align' => 'text-center', 'type' => 'bool', 'tmpTableFilter' => true, 'orderby' => false, ), 'customer' => array( 'title' => $this->trans('Customer', array(), 'Admin.Global'), 'havingFilter' => true, ), ); if (Configuration::get('PS_B2B_ENABLE')) { $this->fields_list = array_merge($this->fields_list, array( 'company' => array( 'title' => $this->trans('Company', array(), 'Admin.Global'), 'filter_key' => 'c!company', ), )); } $this->fields_list = array_merge($this->fields_list, array( 'total_paid_tax_incl' => array( 'title' => $this->trans('Total', array(), 'Admin.Global'), 'align' => 'text-right', 'type' => 'price', 'currency' => true, 'callback' => 'setOrderCurrency', 'badge_success' => true, ), 'payment' => array( 'title' => $this->trans('Payment', array(), 'Admin.Global'), ), 'osname' => array( 'title' => $this->trans('Status', array(), 'Admin.Global'), 'type' => 'select', 'color' => 'color', 'list' => $this->statuses_array, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'order_key' => 'osname', ), 'date_add' => array( 'title' => $this->trans('Date', array(), 'Admin.Global'), 'align' => 'text-right', 'type' => 'datetime', 'filter_key' => 'a!date_add', ), 'id_pdf' => array( 'title' => $this->trans('PDF', array(), 'Admin.Global'), 'align' => 'text-center', 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false, 'remove_onclick' => true, ), )); if (Country::isCurrentlyUsed('country', true)) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT DISTINCT c.id_country, cl.`name` FROM `' . _DB_PREFIX_ . 'orders` o ' . Shop::addSqlAssociation('orders', 'o') . ' INNER JOIN `' . _DB_PREFIX_ . 'address` a ON a.id_address = o.id_address_delivery INNER JOIN `' . _DB_PREFIX_ . 'country` c ON a.id_country = c.id_country INNER JOIN `' . _DB_PREFIX_ . 'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = ' . (int) $this->context->language->id . ') ORDER BY cl.name ASC'); $country_array = array(); foreach ($result as $row) { $country_array[$row['id_country']] = $row['name']; } $part1 = array_slice($this->fields_list, 0, 3); $part2 = array_slice($this->fields_list, 3); $part1['cname'] = array( 'title' => $this->trans('Delivery', array(), 'Admin.Global'), 'type' => 'select', 'list' => $country_array, 'filter_key' => 'country!id_country', 'filter_type' => 'int', 'order_key' => 'cname', ); $this->fields_list = array_merge($part1, $part2); } $this->shopLinkType = 'shop'; $this->shopShareDatas = Shop::SHARE_ORDER; if (Tools::isSubmit('id_order')) { // Save context (in order to apply cart rule) $order = new Order((int) Tools::getValue('id_order')); $this->context->cart = new Cart($order->id_cart); $this->context->customer = new Customer($order->id_customer); } $this->bulk_actions = array( 'updateOrderStatus' => array('text' => $this->trans('Change Order Status', array(), 'Admin.Orderscustomers.Feature'), 'icon' => 'icon-refresh'), ); } public static function getAllGroups($echo,$tr) { $customerGroups = Customer::getGroupsStatic((int)$echo); $group_name = []; foreach ($customerGroups as $id_group) { $group = new Group((int)$id_group,$this->context->language->id); $group_name[] .= $group->name; } return implode(", ",$group_name); } } Edited December 31, 2020 by Alexandre Carette (see edit history) 1 Link to comment Share on other sites More sharing options...
BrahmsFun Posted December 31, 2020 Author Share Posted December 31, 2020 Thank you so much Alexandre for your detailed and fast response, i will try this out as soon as possible. Link to comment Share on other sites More sharing options...
siomosp Posted October 29, 2021 Share Posted October 29, 2021 Hello! May be you can post similar code for adding at admin orders list customer message? thanks! Link to comment Share on other sites More sharing options...
ukbaz Posted November 2, 2021 Share Posted November 2, 2021 Hi AdminOrdersController doesn't exist in Prestashop v1.7.8.0 Is there a way to do this in that version? Thanks Baz 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