6

I want to create custom order state's and in a view use a "button" or a "select list" to toggle those states.

For example I have view that display's a table of all orders that are marked completed. I would like to add a "button" or "select list" to each row so that I can toggle the state for each order.

Can this be done?

2

Check this module Commerce Custom Order Status it can help you with custom statuses.

  • Someone with a higher reputation than me please vote this down. Commerce States are NOT commerce statuses. The hook solution below is the only approach until the day a dedicated module appears. – Peter Clemence Apr 4 '14 at 5:43
  • 1
    Same goes this is not a complete answer actually because this module simply adds a status see drupal.org/node/1816358 still an outstanding issue for this module unfortunately – shaneonabike Nov 16 '14 at 21:19
10

Two things there:

A. Define your custom order states with one of the Order info hooks.

  1. hook_commerce_order_state_info
  2. hook_commerce_order_status_info

B. Create a commerce_order based VBO view and add an operation to change the order state. It won't be a button on each row, just a checkbox or radio button, but you can batch update that way.

Alternatively, edit the order and set it's state on the edit form.

1

I found the documentation on this to be unclear, so for reference, here's an example of adding a status (not state) programmatically. This adds a new "credit card failure" status under the "Cancelled" state.

function mymodule_commerce_order_status_info() {
  $order_statuses['ccfail'] = array(
    'name' => 'ccfail',
    'title' => t('Credit card failure'),
    'state' => 'canceled',
  );

 return $order_statuses;
}
0

I had problems with the code in the previous example but this worked for me as a way to add a new status of 'Refunded' to the existing 'Canceled' State after the existing 'Canceled' status.

function mymodule_commerce_order_status_info_alter(&$order_statuses) {
    $order_statuses['refund'] = array(
            'name' => 'refund',
            'title' => t('Refunded'),
            'state' => 'canceled',
            'cart' => FALSE,
            'weight' => 10,
    );
}

Note that the 'cart' index is required and if you don't included you will get an undefined index error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.