Jump to content
Yzzy

Display COMPANY name in Orders BO tab.

Recommended Posts

Good Morning all!

 

I deal with companies who use different employees to place orders. This means I can't always know that Frank and Jane are ordering for Blah Blah Ltd.

 

I'd like the back office ORDERS tab to display COMPANY NAME before or instead of Customer name please...

 

Anyone have a quick link to how to do this?

 

Yzzy x :D

Share this post


Link to post
Share on other sites

ad.`company` AS `company`,
a.id_order AS id_pdf, 

 

isn't working.. it's kicking up an SQL error...

 

I can yet again see MANY threads all asking this same question but no one is replying with a solution... Im sure there must be other companies out there needing company name in the orders... It would make life so much easier to look down the orders list and look for Blah Blah Ltd rather than clicking on each random name hoping to find the order for Blah Blah ltd... :)

Edited by Yzzy (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

Anyone?

 

I know I can probably find this out myself with a lot of digging about but someone surely must be reading this thinking how easy it is... please share!!

 

:wub:

Share this post


Link to post
Share on other sites

Sheesh.. not even a Presta Mod to say "sorry we don't know"... nice...

Share this post


Link to post
Share on other sites

$this->_select = '

ad.`company` AS `company`,

a.id_order AS id_pdf,

...

LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.`id_customer` = a.`id_customer`)

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

 

 

adding this duplicated my orders in orders tab

Edited by SeVi (see edit history)

Share this post


Link to post
Share on other sites

Thank you Sevi. I'll have a fiddle around with the code a bit later and see if I can get it to collect the needed info from the DB...

Share this post


Link to post
Share on other sites

Let me know if you find fix for duplicated orders with that script.

For now i only managed to add the column and of course it doesnt show anything. BTW i'm trying to display country, not company, so i can see what country is order goes to w/o clicking on each order

Share this post


Link to post
Share on other sites

Try this (bold fonts are changed/added).

AdminOrders.php:

 

 

 

$this->_select = '

a.id_order AS id_pdf,

ad.`company` AS `customer`,

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,

(SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number';

$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)

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

LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)

LEFT JOIN `'._DB_PREFIX_.'address` ad ON (a.`id_address_delivery` = ad.`id_address`)

LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)($cookie->id_lang).')';

$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';

Share this post


Link to post
Share on other sites

I have changed and company column is still empty

 

a.id_order AS id_pdf,

ad.`company` AS `customer`,

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,

(SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number';

$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)

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

LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)

LEFT JOIN `'._DB_PREFIX_.'address` ad ON (a.`id_address_delivery` = ad.`id_address`)

LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)($cookie->id_lang).')';

$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';

Edited by SeVi (see edit history)

Share this post


Link to post
Share on other sites

and here is 2nd part, where i added the column

 

$statesArray = array();

$states = OrderState::getOrderStates((int)($cookie->id_lang));

foreach ($states AS $state)

$statesArray[$state['id_order_state']] = $state['name'];

$this->fieldsDisplay = array(

'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),

'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false),

'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 160, 'width' => 140, 'filter_key' => 'customer', 'tmpTableFilter' => true),

'total_paid' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true),

'payment' => array('title' => $this->l('Payment'), 'width' => 100),

'osname' => array('title' => $this->l('Status'), 'widthColumn' => 230, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 100),

'company' => array('title' => $this->l('Company'), 'width' => 100),

'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),

'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false));

parent::__construct();

Edited by SeVi (see edit history)

Share this post


Link to post
Share on other sites

It was for replacing customer column. It will show only the company name. You should change only the two lines of original file.

I will look adding separate company column later.

Share this post


Link to post
Share on other sites

It was for replacing customer column. It will show only the company name. You should change only the two lines of original file.

I will look adding separate company column later.

 

thanks

i was actually looking for a way to show Country, not a Company. I think i could find a way to do it once i know how to make it show the company

Share this post


Link to post
Share on other sites

This has everything: country, company, customer :)

 

SQL part:

 

$this->_select = '

a.id_order AS id_pdf,

co.`iso_code` AS `country`,

ad.`company` AS `company`,

CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,

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,

(SELECT COUNT(od.`id_order`) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number';

$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)

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

LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)

LEFT JOIN `'._DB_PREFIX_.'address` ad ON (a.`id_address_delivery` = ad.`id_address`)

LEFT JOIN `'._DB_PREFIX_.'country` co ON (ad.`id_country` = co.`id_country`)

LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)($cookie->id_lang).')';

$this->_where = 'AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)';

 

Column part:

 

$this->fieldsDisplay = array(

'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),

'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'new', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => 'news-new.gif'), 'orderby' => false),

'country' => array('title' => $this->l('Country'), 'width' => 20),

'company' => array('title' => $this->l('Company'), 'widthColumn' => 140, 'width' => 100, 'filter_key' => 'company', 'tmpTableFilter' => true),

'customer' => array('title' => $this->l('Customer'), 'widthColumn' => 150, 'width' => 100, 'filter_key' => 'customer', 'tmpTableFilter' => true),

'total_paid' => array('title' => $this->l('Total'), 'width' => 50, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'price' => true, 'currency' => true),

'payment' => array('title' => $this->l('Payment'), 'width' => 50),

'osname' => array('title' => $this->l('Status'), 'widthColumn' => 120, 'type' => 'select', 'select' => $statesArray, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'width' => 120),

'date_add' => array('title' => $this->l('Date'), 'width' => 35, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add'),

'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false));

Share this post


Link to post
Share on other sites

have tried and it does show country and company columns but they are empy and if i use filter i get :Unknown column 'company' in 'where clause'

 

SELECT SQL_CALC_FOUND_ROWS

* FROM (SELECT

a.*,

a.id_order AS id_pdf,

CONCAT(LEFT(c.`firstname`, 1), '. ', c.`lastname`) AS `customer`,

osl.`name` AS `osname`,

os.`color`,

1 AS products,

IF((SELECT COUNT(so.id_order) FROM `ps_orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new,

(SELECT COUNT(od.`id_order`) FROM `ps_order_detail` od WHERE od.`id_order` = a.`id_order` GROUP BY `id_order`) AS product_number

FROM `ps_orders` a

 

LEFT JOIN `ps_customer` c ON (c.`id_customer` = a.`id_customer`)

LEFT JOIN `ps_order_history` oh ON (oh.`id_order` = a.`id_order`)

LEFT JOIN `ps_order_state` os ON (os.`id_order_state` = oh.`id_order_state`)

LEFT JOIN `ps_order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = 1)

WHERE 1 AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `ps_order_history` moh WHERE moh.`id_order` = a.`id_order` GROUP BY moh.`id_order`)

 

HAVING product_number

ORDER BY `date_add` DESC) tmpTable WHERE 1 AND `company` LIKE '%un%'

LIMIT 0,50

Edited by SeVi (see edit history)

Share this post


Link to post
Share on other sites

It is working for me in version 1.4.8. You should write them exactly what I wrote, nothing more or less. Change only lines written in bold font from the original(comes from default downloding) prestashop/admin/tabs/AdminOrders.php file.

Share this post


Link to post
Share on other sites

I checked ver1.4.3 AdminOrders.php file and ver 1.4.8's but couldn't find any important differences, it should work.

Share this post


Link to post
Share on other sites

i've tried 2 times and it displays the columns(country and company) but they're empty , so i placed a test order and both columns were empty again :(

Share this post


Link to post
Share on other sites

Hello, was having trouble with this also

 

This was the cause 'company', 'tmpTableFilter' => true - so have excluded it.

 

But i have it working now with the following code (this is for prestashop 1.5)

 

Brings back the company in the admin orders and can search etc

 

 

SQL part:

 

$this->_select = '

a.id_currency,

ad.`company` AS `company`,

a.id_order AS id_pdf,

CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,

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_.'address` ad ON (a.`id_address_delivery` = ad.`id_address`)

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.')';

 

 

 

 

 

Column part:

 

$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

),

'new' => array(

'title' => $this->l('New'),

'width' => 25,

'align' => 'center',

'type' => 'bool',

'tmpTableFilter' => true,

'icon' => array(

0 => 'blank.gif',

1 => array(

'src' => 'note.png',

'alt' => $this->l('First customer order'),

)

),

'orderby' => false

),

'customer' => array(

'title' => $this->l('Customer'),

'havingFilter' => true,

'widthColumn' => 140,

'width' => 100,

),

'company' => array(

'title' => $this->l('Company'),

'havingFilter' => true,

'widthColumn' => 140,

'width' => 100,

),

'total_paid_tax_incl' => array(

'title' => $this->l('Total'),

'width' => 70,

'align' => 'right',

'prefix' => '<b>',

'suffix' => '</b>',

'type' => 'price',

'currency' => true

),

'payment' => array(

'title' => $this->l('Payment'),

'width' => 100

),

'osname' => array(

'title' => $this->l('Status'),

'color' => 'color',

'width' => 280,

'type' => 'select',

'list' => $statuses_array,

'filter_key' => 'os!id_order_state',

'filter_type' => 'int'

),

'date_add' => array(

'title' => $this->l('Date'),

'width' => 130,

'align' => 'right',

'type' => 'datetime',

'filter_key' => 'a!date_add'

),

'id_pdf' => array(

'title' => $this->l('PDF'),

'width' => 35,

'align' => 'center',

'callback' => 'printPDFIcons',

'orderby' => false,

'search' => false,

'remove_onclick' => true)

);

Edited by ecentury (see edit history)

Share this post


Link to post
Share on other sites

Hi, can anyone tell me how to make this work in 1.5.6.1 ? And how exactly to implement the above???

 

Cheers

Jamie

Share this post


Link to post
Share on other sites

The column management for order list should be a configurable thing. Where do you go to suggest good ideas?

Because if I'm not mistaken all of the changes that will need to be made to get the columns to display will be lost on an update or Prestashop. 

Edited by stnadmin (see edit history)

Share this post


Link to post
Share on other sites

Hi. Can anyone help me add a 'Company' column in the Orders page of the Back Office of version 1.6.0.9?

 

The shop/admin/tabs/ folder is empty (no AdminOrders.php)

 

Under shop/controllers/admin/ there is a AdminOrdersController.php file - is this what needs editing in version 1.6.0.9?

 

Thanks for any help - it is greatly appreciated!

Share this post


Link to post
Share on other sites

I hope this helps others trying to show the Company in the orders or cutomer pages in the back office of prestashop 1.6.0.9...

In shop/controllers/admin/AdminOrdersController.php and shop/controllers/admin/AdminCustomersController.php there is the following bit of code to show the Company name if using B2B mode:

if (Configuration::get('PS_B2B_ENABLE'))
		{
			$this->fields_list = array_merge($this->fields_list, array(
				'company' => array(
					'title' => $this->l('Company')
				),
			));
		}

By changing it to the following, the Company column is displayed anyway:

 
	 
			$this->fields_list = array_merge($this->fields_list, array(
				'company' => array(
					'title' => $this->l('Company')
				),
			));
		 

This should probably be done in an override but I'm not sure how to do that.

Share this post


Link to post
Share on other sites

I hope this helps others trying to show the Company in the orders or cutomer pages in the back office of prestashop 1.6.0.9...

In shop/controllers/admin/AdminOrdersController.php and shop/controllers/admin/AdminCustomersController.php there is the following bit of code to show the Company name if using B2B mode:

if (Configuration::get('PS_B2B_ENABLE'))
		{
			$this->fields_list = array_merge($this->fields_list, array(
				'company' => array(
					'title' => $this->l('Company')
				),
			));
		}

By changing it to the following, the Company column is displayed anyway:

 
	 
			$this->fields_list = array_merge($this->fields_list, array(
				'company' => array(
					'title' => $this->l('Company')
				),
			));
		 

This should probably be done in an override but I'm not sure how to do that.

 

Hello,

You don't need it. B.O -> Preferences -> Customer Settings -> Enable B2B

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More