Discussions

Additional Information on the Order Page

I need to display additional customer information regarding the order when viewed by an admin.

I need to show the date of the order and the customer's email address(among other things).

How would I go about modifying the order page for admins?

Posted: Dec 20, 2011

Comments

rfay Randy Fay on December 20, 2011

You can change the orders page view in any way you want just by editing it. That's the easiest way. If you add fields to the order, they will also show up on the order page.

Also note that the user's email and order history are in fact on the edit page, if that helps you.

tars16 on January 3, 2012

Thanks Randy, I knew I could edit the view but I was going crazy because every time I added a relationship of: Commerce Line Item: Order ID or Commerce Order: Owner it would break the order for the user who placed the order. It would just not show any of the line items.

I was able to work around this by adding and attachment to the default display and overriding the relationships and fields. I added Commerce Line Item: Order ID and Commerce Order: Owner and was able to get the email address and order date from there. I also added a relationship to the order:billing info and got the extra phone number field I added.

I attached the export of the view if anyone wants to take a look.

Also, remember in the views settings, you can 'Always show advanced display settings' to make sure none of the fields or relationships snuck into the default display.

Oh, and for the attachment, I have it restricted to admin and store admin roles, which you may not have. This hides the extra customer info from the customer's view of the order page.

April on February 15, 2016

Would have liked a bit more clarification on what you did here. I'm trying to do the same thing but I have no idea where you added this Commerce Order: Owner attachment at. :-(

aidan on February 8, 2013

Here's an example which adds the users email and the order status to the top of the view order page:

<?php
/**
 * Implements hook_entity_view_alter().
 */
function YOURMODULE_entity_view_alter(&$build, $type) {
  switch (
$type) {
    case
'commerce_order':
      if (
$build['#view_mode'] === 'administrator') {
       
$order = $build['#entity'];
       
       
$build['status'] = array(
         
'#type' => 'fieldset',
         
'#title' => t('Order details'),
         
'#weight' => -100,
        );

       
$build['status']['markup'] = array(
         
'#prefix' => '<dl>',
         
'#suffix' => '</dl>',
          array(
'#markup' => sprintf('<dt>%s</dt><dd>%s<dd>', t('Status'), $order->status)),
          array(
'#markup' => sprintf('<dt>%s</dt><dd>%s<dd>', t('E-mail'), $order->mail)),
        );
      }
      break;
  }
}
?>

Dr.Osd on February 4, 2016

Works great, Thanks!
Additional question, how to print this like div instead of fieldset. Fieldset looks not nice..