You are here

function commerce_shipping_line_item_configuration in Commerce Shipping 7

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

Ensures the shipping line item type contains a field for shipping method.

This function is called by the line item module when it is enabled or this module is enabled. It invokes this function using the configuration_callback as specified above.

1 call to commerce_shipping_line_item_configuration()
commerce_shipping_update_7003 in ./commerce_shipping.install
Rename shipping_method field on line item to commerce_shipping_method.

File

./commerce_shipping.module, line 98
Defines the shipping system and checkout integration.

Code

function commerce_shipping_line_item_configuration() {

  // TODO: Maybe we should create our own field type to reference the shipping
  // method. Since we only want to store its name, list_text should suffice.
  $field = field_info_field('commerce_shipping_method');
  $instance = field_info_instance('commerce_line_item', 'commerce_shipping_method', 'shipping');
  if (empty($field)) {
    $field = array(
      'field_name' => 'commerce_shipping_method',
      'type' => 'list_text',
      'cardinality' => 1,
      'entity_types' => array(
        'commerce_line_item',
      ),
      'translatable' => FALSE,
      'locked' => TRUE,
      'settings' => array(
        'allowed_values_function' => 'commerce_shipping_get_shipping_methods_options',
      ),
    );
    $field = field_create_field($field);
  }
  if (empty($instance)) {
    $instance = array(
      'field_name' => 'commerce_shipping_method',
      'entity_type' => 'commerce_line_item',
      'bundle' => 'shipping',
      'label' => t('Shipping method'),
      'required' => TRUE,
      'settings' => array(),
      'widget' => array(
        'type' => 'options_select',
        'weight' => 0,
      ),
      'display' => array(
        'display' => array(
          'label' => 'hidden',
          'weight' => 0,
        ),
      ),
    );
    field_create_instance($instance);
  }
}