Jump to content

Show Customer group on orders page in backoffice


Recommended Posts

in this case you have to modify AdminOrdersController.php file (/controllers/admin/AdminOrdersController.php)

you've got there code:

$this->_select = '
		a.id_currency,
		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_.'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'; 

change it to:

	$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`, \' (\', gr.`name`, \')\') 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_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`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';

effect:

8X71zHi.png

 

 

J. DOE (customer) - where customer is a group name :)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 6 months later...

Hello,

 

How do i get the state of the customer from the address. With the above reference i am able to get the city of the customer but not able to get the state.

 

Anyone can help me please.

 

Thanks,

 

and you want to display it as a separate row of table, or as i added customer group above?

Link to comment
Share on other sites

one last question because i've noticed something while dealing with code.

customer can select two addresses, one for delivery address, second for invoice

from which one you want to display state?

Link to comment
Share on other sites

one last question because i've noticed something while dealing with code.

customer can select two addresses, one for delivery address, second for invoice

from which one you want to display state?

 

Hello Vekia,

 

I would like to display the state from the delivery address.

 

Thanks,

Link to comment
Share on other sites

okay so you ahve to add these two left joins

        LEFT JOIN `'._DB_PREFIX_.'address` ca ON (a.`id_address_delivery` = ca.`id_address`)
        LEFT JOIN `'._DB_PREFIX_.'state` css ON (ca.`id_state` = css.`id_state`)

then you will be able to use css.name to display state name

Link to comment
Share on other sites

in this case you have to modify AdminOrdersController.php file (/controllers/admin/AdminOrdersController.php)

you've got there code:

$this->_select = '
		a.id_currency,
		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_.'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'; 

change it to:

	$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`, \' (\', gr.`name`, \')\') 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_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`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';

effect:

8X71zHi.png

 

 

J. DOE (customer) - where customer is a group name :)

 

Please this trick for 1.6.0.6

Link to comment
Share on other sites

don't copy whole code, just lines that i added

Yes I add only this line and nothing change

 LEFT JOIN `'._DB_PREFIX_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`id_lang`= '.(int)$this->context->language->id.')
Link to comment
Share on other sites

 

Yes I add only this line and nothing change

 LEFT JOIN `'._DB_PREFIX_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`id_lang`= '.(int)$this->context->language->id.')

I  bit of help please when you can

 

thanks

Link to comment
Share on other sites

okay so you ahve to add these two left joins

        LEFT JOIN `'._DB_PREFIX_.'address` ca ON (a.`id_address_delivery` = ca.`id_address`)
        LEFT JOIN `'._DB_PREFIX_.'state` css ON (ca.`id_state` = css.`id_state`)

then you will be able to use css.name to display state name

 

Hello Vekia,

 

It worked like a charm.

 

Thanks,

Link to comment
Share on other sites

 

Yes I add only this line and nothing change

 LEFT JOIN `'._DB_PREFIX_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`id_lang`= '.(int)$this->context->language->id.')

you have to change also SELECT condition

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
  • 1 month later...
  • 2 months later...
  • 5 months later...

in this case you have to modify AdminOrdersController.php file (/controllers/admin/AdminOrdersController.php)

you've got there code:

$this->_select = '
		a.id_currency,
		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_.'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'; 
change it to:

	$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`, \' (\', gr.`name`, \')\') 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_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`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';
effect:

8X71zHi.png

 

 

J. DOE (customer) - where customer is a group name :)

 

 

 

Hello Vekia,

 

How can i add state in the Customers->Addresses.

 

 

 

Thanks,

Link to comment
Share on other sites

  • 2 months later...

Hi,

 

i have 1.6.0.14 and i added the line: 

 

LEFT JOIN `'._DB_PREFIX_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`id_lang`= '.(int)$this->context->language->id.')

 

but nothing happen, can you tell me what more i have to make?

 

many thanks for your help.

Link to comment
Share on other sites

ok i solved! 

 

but i have a question, this shows the group where is the customer. 

 

i have  a modification where customers can change the group, and for example if they buy with GROUP A, in back office show (Group A), but if after they change to GROUP B and make another order, change all orders before too in back office to GROUP B.

 

thanks

Link to comment
Share on other sites

in this case it will be necessary to store somewhere information what group was used to order stuff from shop.

there is no other way.

if i were you i will add new column to ps_orders table "customer_group" and i will add there this information

then you will be able to display it easily

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • 2 months later...

Hi!

 

I have the same question basically.

Display the group name in the customers listing in the backoffice.

So that my client when viewing his customers knows which group clients are into.

 

I can't manage to make my AdminCustomersController override works. I have found this one but it show only the id. I try to fiddle with your code here but no luck.

 

_______

 

class AdminCustomersController extends AdminCustomersControllerCore

{

  public function __construct()

 

  {

   parent::__construct();

   $this->_select .= ', ca.id_group as group_id';

   $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'customer_group` ca ON (ca.`id_customer` = a.`id_customer`)';

   $this->fields_list['group_id'] = array(

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

   'width' => 200,

   'callback' => 'groupe'

   );

  }

   public function groupe($id_group)

  {

   return $id_group;

  }

}

 

_________

 

If someone knows how to display in a separate column the name of the group on the BO customers list.

 

Best regards,

 

Quentin

Link to comment
Share on other sites

  • 4 months later...
  • 1 year later...

So we did those changes in code and we see customers group and this is pretty cool but if we could sort customers by group like we sorting them by status it will be super helpful to manage orders. Is there any solutions or thoughts ?

Link to comment
Share on other sites

  • 1 year later...
  • 10 months later...

 

 

On 10/15/2013 at 8:00 PM, vekia said:

in this case you have to modify AdminOrdersController.php file (/controllers/admin/AdminOrdersController.php)

you've got there code:


$this->_select = '
		a.id_currency,
		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_.'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'; 

change it to:


	$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`, \' (\', gr.`name`, \')\') 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_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`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';

effect:

8X71zHi.png

 

 

J. DOE (customer) - where customer is a group name :)

 

Edited by antonio_fiorella (see edit history)
Link to comment
Share on other sites

Ciao

facendo la modifica su prestashop 1.7

il sistema mi da questo errore

Query SQL non valida
Unknown column 'country.id_country' in 'field list'

On 10/15/2013 at 8:00 PM, vekia said:

in this case you have to modify AdminOrdersController.php file (/controllers/admin/AdminOrdersController.php)

you've got there code:


$this->_select = '
		a.id_currency,
		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_.'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'; 

change it to:


	$this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`, \' (\', gr.`name`, \')\') 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_.'group_lang` gr ON (gr.`id_group` = c.`id_default_group` AND gr.`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';

effect:

8X71zHi.png

 

 

J. DOE (customer) - where customer is a group name :)

 

Edited by tattichemarketing (see edit history)
Link to comment
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...