Jump to content

Limit the order list AND the order statuses


Recommended Posts

Hello everyone!
Here comes something for you:
I have introduced an attribute (Cost Account Center) for both customers and employees. Now I want the employee of CAC x to see only the orders from customers with CAC x. So I thought I'd hack the AdminOrdersController.php just a little, introducing on row 44 just before the select:
$employee = new Employee((int)$this->context->cookie->id_employee);
and then adding one join:
INNER JOIN `'._DB_PREFIX_.'customer` cu ON (cu.`id_costcenter` = '.$employee->id_costcenter.')


No effect! Every employee continues seeing all orders.


But it doesn't stop here. I also need to display order statuses according to the profile of the employee. I thought this was simple and I spent many hours on trying without success. I modified all the calls to Orderstate like this 


'states' => OrderState::getOrderStates($this->context->language->id, $this->context->cookie->profile)


In the getOrderStates function I read the variable $profile = 1 and then I add a limitation to the query based on the profile id, But it remains always the default 1. The profile id of the employee is never passed.


Any help with this would be much appreciated.


Thank you very much!



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

First of all, I believe that using context->employee data is enough and there is no need to modify the call to OrderState::getOrderStates everywhere. Simply check in your code if context->employee is existing and if so, do your logic directly in getOrderStates, without changing to much code.


Then, to check for the actual query being executed you can either enable _PS_DEBUG_PROFILING_ and check directly on the page, or you could put a ddd($this->_listsql) in classes/controller/AdminController.php on line 2819 just before:


$this->_list = Db::getInstance()->executeS($this->_listsql, true, false);


Take the query and check it in PHPMyAdmin or something to see what results it gives.

Edited by cristic (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...