You are here

function commerce_reorder_reorder_callback in Commerce Reorder 7.2

Same name and namespace in other branches
  1. 7 commerce_reorder.module \commerce_reorder_reorder_callback()

Perform the reorder action for the operations menu

1 string reference to 'commerce_reorder_reorder_callback'
commerce_reorder_menu in ./commerce_reorder.module
Implementation of hook_menu

File

./commerce_reorder.module, line 66
Allows users to create a new order from their order history.

Code

function commerce_reorder_reorder_callback($order) {
  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'commerce_reorder:' . $order->order_id) || !commerce_order_access('view', $order)) {
    return MENU_ACCESS_DENIED;
  }
  $profile_types = commerce_customer_profile_types();
  foreach ($profile_types as $type) {
    $default_profile_options[$type] = TRUE;
  }

  // Ensure that the copied order belongs to the original owner.
  commerce_reorder_helper($order, null, array(
    'copy_profiles' => $default_profile_options,
    'suppress_cart_messages' => TRUE,
  ));
  $new_order = commerce_cart_order_load($order->uid);

  // Redirect to the new order.
  drupal_set_message(t('Order copied.'));
  drupal_goto('admin/commerce/orders/' . $new_order->order_id);
}