You are here

function commerce_shipping_line_item_configuration in Commerce Shipping 7.2

Same name and namespace in other branches
  1. 7 commerce_shipping.module \commerce_shipping_line_item_configuration()

Line item callback: configures the shipping line item type on module enable.

1 call to commerce_shipping_line_item_configuration()
commerce_shipping_update_7100 in ./commerce_shipping.install
Upgrade from Commerce Shipping 1.x.

File

./commerce_shipping.module, line 748
Defines a system for calculating shipping costs associated with an order.

Code

function commerce_shipping_line_item_configuration($line_item_type) {
  $field_name = 'commerce_shipping_service';
  $type = $line_item_type['type'];
  $field = field_info_field($field_name);
  $instance = field_info_instance('commerce_line_item', $field_name, $type);
  if (empty($field)) {
    $field = array(
      'field_name' => $field_name,
      'type' => 'list_text',
      'cardinality' => 1,
      'entity_types' => array(
        'commerce_line_item',
      ),
      'translatable' => FALSE,
      'locked' => TRUE,
      'settings' => array(
        'allowed_values_function' => 'commerce_shipping_service_options_list',
      ),
    );
    $field = field_create_field($field);
  }
  if (empty($instance)) {
    $instance = array(
      'field_name' => $field_name,
      'entity_type' => 'commerce_line_item',
      'bundle' => $type,
      'label' => t('Shipping service'),
      'required' => TRUE,
      'settings' => array(),
      'widget' => array(
        'type' => 'options_select',
        'weight' => 0,
      ),
      'display' => array(
        'display' => array(
          'label' => 'hidden',
          'weight' => 0,
        ),
      ),
    );
    field_create_instance($instance);
  }
}