View source
<?php
function commerce_order_ui_menu() {
$items = array();
$items['admin/commerce/orders/add'] = array(
'title' => 'Create an order',
'description' => 'Create a new order.',
'page callback' => 'commerce_order_ui_order_form_wrapper',
'access callback' => 'commerce_order_access',
'access arguments' => array(
'create',
),
'weight' => 10,
'file' => 'includes/commerce_order_ui.orders.inc',
);
$items['admin/commerce/orders/add/%user'] = array(
'title' => 'Create an order',
'description' => 'Create a new order for the specified user.',
'page callback' => 'commerce_order_ui_order_form_wrapper',
'page arguments' => array(
NULL,
4,
),
'access callback' => 'commerce_order_access',
'access arguments' => array(
'create',
),
'file' => 'includes/commerce_order_ui.orders.inc',
);
$items['admin/commerce/orders/%commerce_order'] = array(
'title callback' => 'commerce_order_ui_order_title',
'title arguments' => array(
3,
),
'page callback' => 'commerce_order_ui_order_view',
'page arguments' => array(
3,
),
'access callback' => 'commerce_order_admin_order_view_access',
'access arguments' => array(
3,
),
);
$items['admin/commerce/orders/%commerce_order/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items['admin/commerce/orders/%commerce_order/edit'] = array(
'title' => 'Edit',
'page callback' => 'commerce_order_ui_order_form_wrapper',
'page arguments' => array(
3,
),
'access callback' => 'commerce_order_access',
'access arguments' => array(
'update',
3,
),
'type' => MENU_LOCAL_TASK,
'weight' => -5,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => 'includes/commerce_order_ui.orders.inc',
);
$items['admin/commerce/orders/%commerce_order/delete'] = array(
'title' => 'Delete',
'page callback' => 'commerce_order_ui_order_delete_form_wrapper',
'page arguments' => array(
3,
),
'access callback' => 'commerce_order_access',
'access arguments' => array(
'delete',
3,
),
'type' => MENU_LOCAL_TASK,
'weight' => 20,
'context' => MENU_CONTEXT_INLINE,
'file' => 'includes/commerce_order_ui.orders.inc',
);
$items['admin/commerce/config/order'] = array(
'title' => 'Order settings',
'description' => 'Configure general order settings, fields, and displays.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'commerce_order_settings_form',
),
'access arguments' => array(
'configure order settings',
),
'file' => 'includes/commerce_order_ui.orders.inc',
);
$items['admin/commerce/config/order/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['user/%user/orders/%commerce_order'] = array(
'title callback' => 'commerce_order_ui_order_title',
'title arguments' => array(
3,
),
'page callback' => 'commerce_order_ui_order_view',
'page arguments' => array(
3,
'customer',
),
'access callback' => 'commerce_order_customer_order_view_access',
'access arguments' => array(
3,
),
);
return $items;
}
function commerce_order_ui_order_title($order) {
return t('Order @number', array(
'@number' => $order->order_number,
));
}
function commerce_order_admin_order_view_access($order) {
return user_access('access administration pages') && commerce_order_access('view', $order);
}
function commerce_order_customer_order_view_access($order) {
if (array_key_exists($order->status, commerce_order_statuses(array(
'cart' => TRUE,
)))) {
return FALSE;
}
return commerce_order_access('view', $order);
}
function commerce_order_ui_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($root_path == 'admin/commerce/orders') {
$item = menu_get_item('admin/commerce/orders/add');
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
if ($root_path == 'user/%/orders/%') {
$order_id = $router_item['original_map'][3];
$item = menu_get_item('admin/commerce/orders/' . $order_id . '/edit');
if ($item['access']) {
$item['title'] = t('Edit this order');
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
}
function commerce_order_ui_i18n_string_list($group) {
if ($group == 'commerce') {
$help = variable_get('commerce_order_help_text', '');
if (!empty($help)) {
$strings['commerce']['order']['help']['create'] = $help;
return $strings;
}
}
}
function commerce_order_ui_help($path, $arg) {
if (strpos($path, 'admin/commerce/orders/add') === 0) {
$help = variable_get('commerce_order_help_text', '');
if (!empty($help)) {
$help = commerce_i18n_string('commerce:order:help:create', $help, array(
'sanitize' => FALSE,
));
return '<p>' . filter_xss_admin($help) . '</p>';
}
}
}
function commerce_order_ui_entity_info_alter(&$entity_info) {
$entity_info['commerce_order']['uri callback'] = 'commerce_order_ui_order_uri';
$entity_info['commerce_order']['bundles']['commerce_order']['admin'] = array(
'path' => 'admin/commerce/config/order',
'real path' => 'admin/commerce/config/order',
'access arguments' => array(
'configure order settings',
),
);
}
function commerce_order_ui_order_uri($order) {
$uri = commerce_order_uri($order);
if (!empty($uri)) {
return $uri;
}
if (commerce_order_admin_order_view_access($order)) {
return array(
'path' => 'admin/commerce/orders/' . $order->order_id,
);
}
return NULL;
}
function commerce_order_ui_forms($form_id, $args) {
$forms = array();
$forms['commerce_order_ui_order_form'] = array(
'callback' => 'commerce_order_order_form',
);
$forms['commerce_order_ui_order_delete_form'] = array(
'callback' => 'commerce_order_order_delete_form',
);
return $forms;
}
function commerce_order_ui_form_commerce_order_ui_order_form_alter(&$form, &$form_state) {
$form['actions']['submit']['#submit'][] = 'commerce_order_ui_order_form_submit';
$form['actions']['submit']['#suffix'] = l(t('Cancel'), 'admin/commerce/orders');
}
function commerce_order_ui_order_form_submit($form, &$form_state) {
if ($form_state['triggering_element']['#value'] === t('Save order', array(), array(
'context' => 'a drupal commerce order',
))) {
drupal_set_message(t('Order saved.'));
$form_state['redirect'] = 'admin/commerce/orders/' . $form_state['commerce_order']->order_id . '/edit';
}
}
function commerce_order_ui_form_commerce_order_ui_order_delete_form_alter(&$form, &$form_state) {
$form['actions']['cancel']['#href'] = 'admin/commerce/orders';
$form['#submit'][] = 'commerce_order_ui_order_delete_form_submit';
}
function commerce_order_ui_order_delete_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/commerce/orders';
}
function commerce_order_ui_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'commerce_order_ui') . '/includes/views',
);
}
function commerce_order_ui_set_breadcrumb($view_mode = 'administrator') {
}
function commerce_order_ui_order_view($order, $view_mode = 'administrator') {
drupal_add_css(drupal_get_path('module', 'commerce_order') . '/theme/commerce_order.theme.css');
return entity_view('commerce_order', array(
$order->order_id => $order,
), $view_mode, NULL, TRUE);
}
function commerce_order_ui_form_entity_translation_admin_form_alter(&$form, &$form_state, $form_id) {
unset($form['entity_translation_entity_types']['#options']['commerce_order']);
}
function commerce_order_ui_redirect_form($form, &$form_state, $redirect_page = 'admin', $identifier = 'order_number') {
$form['#attached']['css'][] = drupal_get_path('module', 'commerce_order') . '/theme/commerce_order.admin.css';
if ($identifier == 'select') {
$form['identifier'] = array(
'#type' => 'select',
'#title' => t('Specify order by', array(), array(
'context' => 'a drupal commerce order',
)),
'#options' => array(
'order_number' => t('Order number', array(), array(
'context' => 'a drupal commerce order',
)),
'order_id' => t('Order ID', array(), array(
'context' => 'a drupal commerce order',
)),
),
'#default_value' => 'order_number',
);
$order_title = t('Order', array(), array(
'context' => 'a drupal commerce order',
));
}
else {
$form['identifier'] = array(
'#type' => 'value',
'#value' => $identifier,
);
if ($identifier == 'order_number') {
$order_title = t('Order number', array(), array(
'context' => 'a drupal commerce order',
));
}
else {
$order_title = t('Order ID', array(), array(
'context' => 'a drupal commerce order',
));
}
}
$form['order_identifier'] = array(
'#type' => 'textfield',
'#title' => $order_title,
'#size' => 16,
);
$form['order'] = array(
'#type' => 'value',
'#value' => NULL,
);
if ($redirect_page == 'select') {
$form['redirect_page'] = array(
'#type' => 'select',
'#title' => t('Redirect page'),
'#options' => array(
'admin' => t('Admin view page'),
'customer' => t('Customer view page'),
),
'#default_value' => 'admin',
);
}
else {
$form['redirect_page'] = array(
'#type' => 'value',
'#value' => $redirect_page,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('View order'),
);
return $form;
}
function commerce_order_ui_redirect_form_validate($form, &$form_state) {
$order = FALSE;
if ($form_state['values']['identifier'] == 'order_number') {
$order = commerce_order_load_by_number($form_state['values']['order_identifier']);
}
elseif ($form_state['values']['identifier'] == 'order_id') {
$order = commerce_order_load($form_state['values']['order_identifier']);
}
if (empty($order) || !commerce_order_access('view', $order)) {
form_set_error('order', t('You have specified an invalid order.'));
}
else {
form_set_value($form['order'], $order, $form_state);
}
}
function commerce_order_ui_redirect_form_submit($form, &$form_state) {
$order = $form_state['values']['order'];
if ($form_state['values']['redirect_page'] == 'admin') {
$form_state['redirect'] = 'admin/commerce/orders/' . $order->order_id;
}
elseif ($form_state['values']['redirect_page'] == 'customer') {
$form_state['redirect'] = 'user/' . $order->uid . '/orders/' . $order->order_id;
}
}