How to assign orders to a manager ?
Hi,
For various reasons, when the customer submit an order, I need to assign the order to a manager, who will be responsible for the post-processing of the order submitted.
In our case, the manager of an order can be changed, and I need to be able to track the manager(s) on a specific order.
I am wondering what will be the best practice for a system like this.
Thanks in advance for your suggestions.
Comments
Orders are entities and
Orders are entities and entities are fieldable. So if you have order-level information, why not add a multi-value field to the order? Perhaps an entity-reference field for user entities ... and then you could set up rules to assign default people to Orders, notify those people that are assigned that they have orders waiting, create views that filter orders based on status and referenced user... etc...
Josh
Thanks, Josh. I am working on
Thanks, Josh. I am working on the direction that you suggested, however have a few questions as follows:
1) If a user reference field is added to the order entity, how could I track the history of assignment? Since at day1 the order is with to Manager1, and at day2 it can be re-assigned to Manager2;
2) If a Manager declines the order, originally assigned to him/her, how could I collect the information (reason why it is declined) and store it together with the history of assignment?
Thanks again for your suggestion, and I am hoping to hear from you soon.
One more question I would
One more question I would like to ask here is that, how could I grant the permission to order manager, so that he/she can view/edit the order under his/her name.
This is similar to the "Node access user reference" module, and I have no idea how to do this in drupal commerce.
Any suggestions are very much appreciated!
Thanks.
My first thought was: https:/
My first thought was: https://drupal.org/project/workbench
But it turns out workbench is a "Node-only" setup.
Back to Google. Found a gem! It's called "Workflow" and it has been fully matured on Drupal 7 ... basically it gives you a field you can add to your Orders to manage "states" and I assume you could use roles and rules to react to those states to control "access."
https://www.drupal.org/project/workflow
Please report back with success/failure. This is a very interesting use case of Drupal's entity system and Commerce's Orders.
Josh
Hi Josh,
Hi Josh,
I am not sure about the workflow project as you mentioned, since all I want is the permission for order manager, however, workflow provides some states for the order. [Can you please correct me if I am wrong about it]
My current solution is to write my custom module utilizing the api that commerce module provides. Attached are the implementations that work for my purpose:
function commerce_order_management_commerce_entity_access_condition_commerce_order_alter(&$conditions, &$context) {
global $user;
$assigned_order_ids = commerce_order_management_assigned_order_ids($user);
// If the user has access to view his own orders of any bundle...
if (user_access('view own ' . $context['entity_type'] . ' entities', $context['account'])) {
// Add a condition granting the user view access
$conditions->condition($context['base_table'] . '.order_id', $assigned_order_ids, 'IN');
}
}
function commerce_order_management_assigned_order_ids($account){
if( is_numeric($account) ){
$assignee_uid_insearch = $account;
}
else {
$assignee_uid_insearch = $account->uid;
}
$assigned_order_ids = array();
$orders = commerce_order_load_multiple(array(), array('status'=>'pending'), TRUE);
if(empty($orders)){
return $assigned_order_ids;
}
foreach( $orders as $order_id => $order ){
$assignee_uid = $order->field_order_assignee['und'][0]['uid']; // note field_order_assignee is created manually, and hard coded here
if( $assignee_uid == $assignee_uid_insearch )
array_push($assigned_order_ids,$order_id);
}
return $assigned_order_ids;
}