mayna Posted April 17, 2015 Share Posted April 17, 2015 (edited) hy there, i'm using prestashop 1.5.3.1 and i'm trying to show in the admin orders list a column with the vouched info used in the order(name or code or description) but i can't seem to figure this one out in the order controller.i'm trying to do this in the adminorderscontroller with $this->fields_list PLEASE HELP Edited April 17, 2015 by mayna (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted April 18, 2015 Share Posted April 18, 2015 Hi Mayna, You were on the right way :-) Edit, (or even better, override ) file /controllers/admin/AdminOrdersController.php (Make backup!!) In function __construct, add the red code: (Sample code from PS 1.5.4.1, will be very similar to your version) public function __construct() { $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); $this->explicitSelect = true; $this->allow_export = true; $this->deleted = false; $this->context = Context::getContext(); $this->_select = ' a.id_currency, a.id_order AS id_pdf, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, (SELECT GROUP_CONCAT(`name` separator ", ") FROM `'._DB_PREFIX_.'order_cart_rule` ocrt WHERE a.id_order = ocrt.id_order) as `voucher`, osl.`name` AS `osname`, os.`color`, IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new'; $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) 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->fields_list = array( 'id_order' => array( 'title' => $this->l('ID'), 'align' => 'center', 'width' => 25 ), 'reference' => array( 'title' => $this->l('Reference'), 'align' => 'center', 'width' => 65 ), 'voucher' => array( 'title' => $this->l('Voucher(s)'), 'align' => 'center', 'width' => 65 ), 'new' => array( ... Result: If your customers have used more than one voucher per order, they will all be shown (the row will expand in height automatically, to make place for them) Result (Sorry, little cheating, image from PS 1.6.0.14, as I was lazy to make new cart rules + orders. Code is exactly the same for PS 1.6, though) Hope this is what you needed, pascal Link to comment Share on other sites More sharing options...
pawiust Posted December 20, 2015 Share Posted December 20, 2015 Hi Mayna, You were on the right way :-) Edit, (or even better, override ) file /controllers/admin/AdminOrdersController.php (Make backup!!) In function __construct, add the red code: (Sample code from PS 1.5.4.1, will be very similar to your version) public function __construct() { $this->table = 'order'; $this->className = 'Order'; $this->lang = false; $this->addRowAction('view'); $this->explicitSelect = true; $this->allow_export = true; $this->deleted = false; $this->context = Context::getContext(); $this->_select = ' a.id_currency, a.id_order AS id_pdf, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, (SELECT GROUP_CONCAT(`name` separator ", ") FROM `'._DB_PREFIX_.'order_cart_rule` ocrt WHERE a.id_order = ocrt.id_order) as `voucher`, osl.`name` AS `osname`, os.`color`, IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new'; $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) 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->fields_list = array( 'id_order' => array( 'title' => $this->l('ID'), 'align' => 'center', 'width' => 25 ), 'reference' => array( 'title' => $this->l('Reference'), 'align' => 'center', 'width' => 65 ), 'voucher' => array( 'title' => $this->l('Voucher(s)'), 'align' => 'center', 'width' => 65 ), 'new' => array( ... Result: Voucher codes in Admin Orders grid.png If your customers have used more than one voucher per order, they will all be shown (the row will expand in height automatically, to make place for them) Result (Sorry, little cheating, image from PS 1.6.0.14, as I was lazy to make new cart rules + orders. Code is exactly the same for PS 1.6, though) Voucher more than one.png Hope this is what you needed, pascal Thx. When I want to show the code with cart_rule. I used something like this: ... a.id_currency, a.id_order AS id_pdf, CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, (SELECT GROUP_CONCAT(`code` separator ", ") FROM `'._DB_PREFIX_.'cart_rule` ocrt WHERE a.id_cart_rule = ocrt.id_cart_rule) as `voucher`, 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'; ... And this doesn't work :/ Can you help you ? Link to comment Share on other sites More sharing options...
hammerleit Posted February 24, 2016 Share Posted February 24, 2016 @PascalVG Your Code above works fine, but if you search for voucher code in the field above the System hangs Error: unknown column 'voucher' in 'where clause' btw: is there any possibility to Show the voucher code instead of the voucher name? Link to comment Share on other sites More sharing options...
DannetStudio Posted December 5, 2019 Share Posted December 5, 2019 (edited) On 2/24/2016 at 10:50 AM, hammerleit said: @PascalVG btw: is there any possibility to Show the voucher code instead of the voucher name? In PS 1.6, the used cart rule / voucher ID associated to an order is saved on the table order_cart_rule, but in this table is stored only the voucher name, not the voucher code. The code is stored on table cart_rule, so you need to obtain first the cart rule ID associated with the order, and go to the cart_rule table and look for the code asociated with that ID. I've added a column with the voucher code used in admin order list using overrides, that is recommended, so the code changes (actually the way in which it is implemented), with respect to the initial examples of this thread: class AdminOrdersController extends AdminOrdersControllerCore { public function __construct() { parent::__construct(); $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'order_cart_rule` ocrt ON (ocrt.`id_order` = a.`id_order`)'; $this->_select = 'ocrt.`id_cart_rule` AS `coupon_id`,'.$this->_select; $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'cart_rule` cr ON (cr.`id_cart_rule` = ocrt.`id_cart_rule`)'; $this->_select = 'cr.`code` AS `voucher_code`,'.$this->_select; $this->fields_list['voucher_code'] = array('title' => 'Voucher Code', 'align' => 'center', 'width' => 65, 'havingFilter' => true ); } } It should be placed on a new file called AdminOrdersControllers.php, in folder /override/controllers/admin Regards, Daniel Edited December 5, 2019 by DannetStudio (see edit history) 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