Page 1 of 2

Add Customer Group field to Orders List

Posted: Fri Dec 09, 2011 4:45 am
by bbaccessories
We need to manage order processing & dispatch by customer group. So we need to filter the Order List by Customer Group before we can really begin processing orders.

Does anyone know a way of adding this Customer Group Column to the Order List (it is already present on the Customer List)?

Thanks

Re: Add Customer Group field to Orders List

Posted: Fri Dec 09, 2011 6:59 am
by straightlight
Make a backup of the followings before doing anything.

In admin/controller/sale/order.php file,

find all instances of:

Code: Select all

if (isset($this->request->get['filter_customer'])) {
				$url .= '&filter_customer=' . $this->request->get['filter_customer'];
			}
add after each results found:

Code: Select all

if (isset($this->request->get['filter_group_customer'])) {
				$url .= '&filter_group_customer=' . $this->request->get['filter_group_customer'];
			}
// Update: December 26, 2014

Find all instances of:

Code: Select all

if (isset($this->request->get['filter_customer'])) {
			$filter_customer = $this->request->get['filter_customer'];
		} else {
			$filter_customer = null;
		}
add after:

Code: Select all

if (isset($this->request->get['filter_group_customer'])) {
			$filter_group_customer = $this->request->get['filter_group_customer'];
		} else {
			$filter_group_customer = null;
		}
// End Of December 26, 2014 Update

Then, find all instances of:

Code: Select all

'filter_customer'	     => $filter_customer,
add after each results found:

Code: Select all

'filter_group_customer'	     => $filter_group_customer,
Then, find:

Code: Select all

'customer'      => $result['customer'],
add after:

Code: Select all

'group_customer'      => $result['group_customer'],
Then, find:

Code: Select all

$this->data['column_customer'] = $this->language->get('column_customer');
add after:

Code: Select all

$this->data['column_group_customer'] = $this->language->get('column_group_customer');
Then, find:

Code: Select all

$this->data['sort_customer'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=customer' . $url, 'SSL');
add after:

Code: Select all

$this->data['sort_group_customer'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=group_customer' . $url, 'SSL');
In admin/language/english/sale/order.php file,

find:

Code: Select all

$_['column_customer']         = 'Customer';
add after:

Code: Select all

$_['column_group_customer']         = 'Customer Groups';
In admin/model/sale/order.php file,

find:

Code: Select all

'customer',
add after:

Code: Select all

'group_customer',
find:

Code: Select all

$sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS status, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
replace with:

Code: Select all

$sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.customer_group_id AS group_customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS status, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
Then, find:

Code: Select all

if (!empty($data['filter_customer'])) {
			$sql .= " AND LCASE(CONCAT(o.firstname, ' ', o.lastname)) LIKE '" . $this->db->escape(utf8_strtolower($data['filter_customer'])) . "%'";
		}
add after:

Code: Select all

if (isset($data['filter_group_customer']) && !empty($data['filter_group_customer'])) {
	$sql .= " AND o.customer_group_id = '" . (int)$data['filter_group_customer'] . "'";
} else {
	$sql .= " AND o.customer_group_id > '0'";
}
In admin/view/template/sale/order_list.tpl file,

find:

Code: Select all

<td class="left"><?php if ($sort == 'customer') { ?>
                <a href="<?php echo $sort_customer; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_customer; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_customer; ?>"><?php echo $column_customer; ?></a>
                <?php } ?></td>
add after:

Code: Select all

<td class="left"><?php if ($sort == 'group_customer') { ?>
                <a href="<?php echo $sort_group_customer; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_group_customer; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_group_customer; ?>"><?php echo $column_group_customer; ?></a>
                <?php } ?></td>
Then, find:

Code: Select all

<td><input type="text" name="filter_customer" value="<?php echo $filter_customer; ?>" /></td>
add after:

Code: Select all

<td><input type="text" name="filter_group_customer" value="<?php echo $filter_group_customer; ?>" /></td>
Then, find:

Code: Select all

<td class="left"><?php echo $order['customer']; ?></td>
add after:

Code: Select all

<td class="left"><?php echo $order['group_customer']; ?></td>
Then, find:

Code: Select all

var filter_customer = $('input[name=\'filter_customer\']').attr('value');
	
	if (filter_customer) {
		url += '&filter_customer=' + encodeURIComponent(filter_customer);
	}
add after:

Code: Select all

var filter_group_customer = $('input[name=\'filter_group_customer\']').attr('value');
	
	if (filter_group_customer) {
		url += '&filter_group_customer=' + encodeURIComponent(filter_group_customer);
	}
Remember to do a backup of all these files before proceeding. This is a massive request.

Re: Add Customer Group field to Orders List

Posted: Fri Dec 09, 2011 4:20 pm
by bbaccessories
Hi Straightlight

Wow! Thank you! This really IS MASSIVE!!!

I would not be confident enough to do this on my own at all. Would you charge a fee?

Re: Add Customer Group field to Orders List

Posted: Sat Dec 10, 2011 12:30 am
by straightlight
Send me a PM regarding this integration.

Re: Add Customer Group field to Orders List

Posted: Fri Aug 24, 2012 1:55 am
by Strangeman
This has been one of the most useful posts I have found so far ! Thank you!!. By following through the steps you have outlined, I have gained a lot more insight into how Opencart works, and have managed to adapt your instructions to have a column in the order list to filter by store_id (although there were a couple of places where things might have changed since you wrote this, so it didn't work straight away). The one remaining difficulty I have found, though, is that the default store has an id of '0' which doesn't seem to filter anything. Is there a way around this ?

Re: Add Customer Group field to Orders List

Posted: Tue Sep 11, 2012 12:22 am
by straightlight
Strangeman wrote:This has been one of the most useful posts I have found so far ! Thank you!!. By following through the steps you have outlined, I have gained a lot more insight into how Opencart works, and have managed to adapt your instructions to have a column in the order list to filter by store_id (although there were a couple of places where things might have changed since you wrote this, so it didn't work straight away). The one remaining difficulty I have found, though, is that the default store has an id of '0' which doesn't seem to filter anything. Is there a way around this ?
Good point. I will send the updated shortly.

Re: Add Customer Group field to Orders List

Posted: Wed Jan 09, 2013 4:09 pm
by DannyMacD
is there a possibility this could be a VQMod?

also would this work with 1.5.4.1?

Re: Add Customer Group field to Orders List

Posted: Wed Feb 20, 2013 3:51 am
by DannyMacD
is there a possibility this could be a VQMod?

also would this work with 1.5.4.1?

Re: Add Customer Group field to Orders List

Posted: Thu Aug 22, 2013 9:31 pm
by pozpoz
I tried to make o vqmod of this. Partially works. But there is one 'undefined variable' and I dont know how to deal with it. Maybe someone could check this?

I'm working on 1.5.4.1

Re: Add Customer Group field to Orders List

Posted: Thu Aug 22, 2013 10:41 pm
by pozpoz
I forgot about english language (i'm working with polish). I updated file for english too.

Re: Add Customer Group field to Orders List

Posted: Fri Aug 23, 2013 6:47 pm
by pozpoz
Anyone?

Re: Add Customer Group field to Orders List

Posted: Sat Sep 14, 2013 12:06 am
by straightlight
I will post an update, shortly.

Re: Add Customer Group field to Orders List

Posted: Wed Nov 20, 2013 11:22 pm
by emmetje
Any update on this?

Code: Select all

I've this error: Notice: Undefined variable: filter_group_customer in /home/***/domains/***/public_html/vqmod/vqcache/vq2-admin_controller_sale_order.php on line 317
Thanks in advance!

Re: Add Customer Group field to Orders List

Posted: Wed Nov 20, 2013 11:32 pm
by straightlight
Please post an attachment of that file so to see what might be the variable issue you're reporting about

Re: Add Customer Group field to Orders List

Posted: Thu Nov 21, 2013 12:36 am
by emmetje
Thanks for the really quick reply, it's a vqmod with your code from post 2, i'm using 1.5.3.1 btw...

Re: Add Customer Group field to Orders List

Posted: Thu Nov 21, 2013 12:42 am
by emmetje
And the order.php file

Re: Add Customer Group field to Orders List

Posted: Mon Nov 25, 2013 7:56 pm
by emmetje
straightlight wrote:Please post an attachment of that file so to see what might be the variable issue you're reporting about
Any luck?

Re: Add Customer Group field to Orders List

Posted: Wed Nov 27, 2013 4:44 pm
by emmetje

Re: Add Customer Group field to Orders List

Posted: Sat Dec 20, 2014 11:15 am
by kelemvor
Sorry to bump an old thread but I haven't had any responses to posts I've made so I'm hoping someone can help.

I'm using 1.5.5.1.

I tried the VQMod and the order page wouldn't load at all. I then tried this manually and the page loads up in the Filter box for Customer Group it says:

<b>Notice</b>: Undefined variable: filter_group_customer in <b>/public_html/store/vqmod/vqcache/vq2-admin_view_template_sale_order_list.tpl</b> on line <b>76</b>

I don't use the VQMod for this so I don't know why it's looking in there but when I open up that file, the error line is:

Code: Select all

<td><input type="text" name="filter_group_customer" value="<?php echo $filter_group_customer; ?>" /></td>
Anyone else get this figured out?

Re: Add Customer Group field to Orders List

Posted: Sat Dec 27, 2014 8:18 am
by straightlight
kelemvor wrote:Sorry to bump an old thread but I haven't had any responses to posts I've made so I'm hoping someone can help.

I'm using 1.5.5.1.

I tried the VQMod and the order page wouldn't load at all. I then tried this manually and the page loads up in the Filter box for Customer Group it says:

<b>Notice</b>: Undefined variable: filter_group_customer in <b>/public_html/store/vqmod/vqcache/vq2-admin_view_template_sale_order_list.tpl</b> on line <b>76</b>

I don't use the VQMod for this so I don't know why it's looking in there but when I open up that file, the error line is:

Code: Select all

<td><input type="text" name="filter_group_customer" value="<?php echo $filter_group_customer; ?>" /></td>
Anyone else get this figured out?
Fixed from 2nd post. Follow the red update step.