Jump to content

Edit History

Kami Solutions

Kami Solutions

Hi,

 

I've been looking for a way to show the employee that modified an order in the orders page and filter it but without success, anyone can help?

UPDATE:

I've managed to join the employee but now i have duplicated orders with different status since the employee is obtained from ps_order_history, how can I get the latest update from date_add? I've been thinking of just doing a MAX(date_add) but I'm not pretty sure where to put it...

Here is my code modification (PrestaShopFolder/controllers/admin/AdminOrdersController.php)

$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`,
		osl.`name` AS `osname`,
		os.`color`,
		CONCAT(e.`firstname`, \' \', e.`lastname`) AS `employee`,
		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_history` oh ON (oh.`id_order` = a.`id_order`)
		LEFT JOIN `' . _DB_PREFIX_ . 'employee` e ON (e.`id_employee` = oh.`id_employee`)
		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',
            ),
            '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,
            ),
            'employee' => array(
                'title' => $this->trans('Employee', array(), 'Admin.Global'),
                'havingFilter' => true,
            ),
        );

As you can see, first I select the name and surname of the employee.

CONCAT(e.`firstname`, \' \', e.`lastname`) AS `employee`,

Then I join the tables ps_order_history, ps_employee and ps_orders

LEFT JOIN `' . _DB_PREFIX_ . 'order_history` oh ON (oh.`id_order` = a.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'employee` e ON (e.`id_employee` = oh.`id_employee`)

Finally I show it like a customer to be able to filter the orders created by an employee

'employee' => array(
                'title' => $this->trans('Employee', array(), 'Admin.Global'),
                'havingFilter' => true,
            ),

But how can I get the latest order updates???

Regards

Kami Solutions

Kami Solutions

Hi,

 

I've been looking for a way to show the employee that modified an order in the orders page and filter it but without success, anyone can help?

UPDATE:

I've managed to join the employee but now i have duplicated orders with different status since the employee is obtained from ps_order_history, how can I get the latest update from date_add? I've been thinking of just doing a MAX(date_add) but I'm not pretty sure where to put it...

Here is my code modification (PrestaShopFolder/controllers/admin/AdminOrdersController.php)

$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`,
		osl.`name` AS `osname`,
		os.`color`,
		CONCAT(e.`firstname`, \' \', e.`lastname`) AS `employee`,
		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_history` oh ON (oh.`id_order` = a.`id_order`)
		LEFT JOIN `' . _DB_PREFIX_ . 'employee` e ON (e.`id_employee` = oh.`id_employee`)
		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',
            ),
            '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,
            ),
            'employee' => array(
                'title' => $this->trans('Employee', array(), 'Admin.Global'),
                'havingFilter' => true,
            ),
        );

As you can see, first I select the name and surname of the employee.

CONCAT(e.`firstname`, \' \', e.`lastname`) AS `employee`,

Then I join the tables ps_order_history, ps_employee and ps_orders

LEFT JOIN `' . _DB_PREFIX_ . 'order_history` oh ON (oh.`id_order` = a.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'employee` e ON (e.`id_employee` = oh.`id_employee`)

Finally I show it like a customer to be able to filter the orders created by an employee

'employee' => array(
                'title' => $this->trans('Employee', array(), 'Admin.Global'),
                'havingFilter' => true,
            ),

But how can I get the latest order updates???

Regards

Kami Solutions

Kami Solutions

Hi,

 

I've been looking for a way to show the employee that modified an order in the orders page and filter it but without success, anyone can help?

UPDATE:

I've managed to join the employee but now i have duplicated orders with different status since the employee is obtained from ps_order_history, how can I get the latest update from date_add? I've been thinking of just doing a MAX(date_add) but I'm not pretty sure where to put it...

Here is my code modification:

$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`,
		osl.`name` AS `osname`,
		os.`color`,
		CONCAT(e.`firstname`, \' \', e.`lastname`) AS `employee`,
		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_history` oh ON (oh.`id_order` = a.`id_order`)
		LEFT JOIN `' . _DB_PREFIX_ . 'employee` e ON (e.`id_employee` = oh.`id_employee`)
		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',
            ),
            '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,
            ),
            'employee' => array(
                'title' => $this->trans('Employee', array(), 'Admin.Global'),
                'havingFilter' => true,
            ),
        );

As you can see, first I select the name and surname of the employee.

CONCAT(e.`firstname`, \' \', e.`lastname`) AS `employee`,

Then I join the tables ps_order_history, ps_employee and ps_orders

LEFT JOIN `' . _DB_PREFIX_ . 'order_history` oh ON (oh.`id_order` = a.`id_order`)
LEFT JOIN `' . _DB_PREFIX_ . 'employee` e ON (e.`id_employee` = oh.`id_employee`)

Finally I show it like a customer to be able to filter the orders created by an employee

'employee' => array(
                'title' => $this->trans('Employee', array(), 'Admin.Global'),
                'havingFilter' => true,
            ),

But how can I get the latest order updates???

Regards

Kami Solutions

Kami Solutions

Hi,

 

I've been looking for a way to show the employee that modified an order in the orders page and filter it but without success, anyone can help?

Thanks!

Regards

Kami Solutions

Kami Solutions

Hi,

 

I've been looking for a way to show the employee that modified an order in the orders page and filter it but without success, since the architecture migrated to symfony and AdminOrderController.php is no longer present in 1.7 onwards, all solutions I came with are for 1.6.

Regards

×
×
  • Create New...