Score:0

How can I access or expose the Commerce data in $order->data[] to the Rules module?

us flag

Following this old checkout_pane_example.module tutorial, I created a custom Drupal 7 Commerce checkout pane. It's simply a text field to collect special order instructions from the customer.

function checkout_pane_example_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {

  $pane_form['nickname'] = array(
    '#type' => 'textfield', 
    '#title' => t('Your nickname'), 
    '#description' => t("We'd like to call you by your nickname."), 
    '#default_value' => !empty($order->data['nickname']) ? $order->data['nickname'] : '', 
    '#required' => TRUE,
  );

  return $pane_form;
}

The pane works fine. Anything that's saved in the text area is then stored in $order->data['nickname'].

The problem is that I need to access the data in Rules so I can attach it to the existing email that's sent out on order completion email.

How can I access or expose that data via the Rules module?

apaderno avatar
us flag
The link returns a *Server not found* error.
Score:0
it flag

You can't really expose data as such, but you can define your own order property via hook_entity_property_info() with a custom callback that returns the specific value from the data array you want.

For an example, take a look at commerce_order_entity_property_info()'s definition of the mail_username property and the related commerce_order_get_properties() callback.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.