You are here

function commerce_order_configure_order_type in Commerce Core 7

Ensures the line item field is present on the default order bundle.

1 call to commerce_order_configure_order_type()
commerce_order_enable in modules/order/commerce_order.module
Implements hook_enable().

File

modules/order/commerce_order.module, line 152
Defines the core Commerce order entity and API functions to manage orders and interact with them.

Code

function commerce_order_configure_order_type($type = 'commerce_order') {

  // Look for or add a line item reference field to the order type.
  $field_name = 'commerce_line_items';
  commerce_activate_field($field_name);
  field_cache_clear();
  $field = field_info_field($field_name);
  $instance = field_info_instance('commerce_order', $field_name, $type);
  if (empty($field)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'commerce_line_item_reference',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
      'entity_types' => array(
        'commerce_order',
      ),
      'translatable' => FALSE,
      'locked' => TRUE,
    );
    $field = field_create_field($field);
  }
  if (empty($instance)) {
    $instance = array(
      'field_name' => $field_name,
      'entity_type' => 'commerce_order',
      'bundle' => $type,
      'label' => t('Line items'),
      'settings' => array(),
      'widget' => array(
        'type' => 'commerce_line_item_manager',
        'weight' => -10,
      ),
      'display' => array(),
    );

    // Set the default display formatters for various view modes.
    foreach (array(
      'default',
      'customer',
      'administrator',
    ) as $view_mode) {
      $instance['display'][$view_mode] = array(
        'label' => 'hidden',
        'type' => 'commerce_line_item_reference_view',
        'weight' => -10,
      );
    }
    field_create_instance($instance);
  }

  // Add the order total price field.
  commerce_price_create_instance('commerce_order_total', 'commerce_order', $type, t('Order total'), -8, FALSE, array(
    'type' => 'commerce_price_formatted_components',
  ));

  // Add the customer profile reference fields for each profile type.
  foreach (commerce_customer_profile_types() as $customer_profile_type => $profile_type) {
    commerce_order_configure_customer_profile_type($customer_profile_type, $profile_type['name'], $type);
  }
}