You are here

function commerce_gc_product_line_item_configuration in Commerce GC 7

1 string reference to 'commerce_gc_product_line_item_configuration'
commerce_gc_product_commerce_line_item_type_info_alter in modules/commerce_gc_product/commerce_gc_product.module

File

modules/commerce_gc_product/commerce_gc_product.module, line 232
Provides Giftcard product type and support.

Code

function commerce_gc_product_line_item_configuration($line_item_type) {

  // Run the product line item configuration
  commerce_product_line_item_configuration($line_item_type);
  $type = $line_item_type['type'];
  field_info_cache_clear();
  $fields = field_info_fields();
  $instances = field_info_instances();

  /*
   * Giftcard mail
   */
  if (empty($fields['commerce_gc_mail'])) {

    // Create max uses field.
    $field = array(
      'field_name' => 'commerce_gc_mail',
      'type' => 'email',
      'locked' => FALSE,
      'cardinality' => '1',
    );
    field_create_field($field);
  }
  if (empty($instances['commerce_line_item'][$type]['commerce_gc_mail'])) {
    $instance = array(
      'field_name' => 'commerce_gc_mail',
      'entity_type' => 'commerce_line_item',
      'bundle' => $type,
      'label' => t('Recipient email'),
      'commerce_cart_settings' => array(
        'field_access' => 1,
      ),
    );
    field_create_instance($instance);
  }

  /*
   * Giftcard message
   */
  if (empty($fields['commerce_gc_message'])) {

    // Create max uses field.
    $field = array(
      'field_name' => 'commerce_gc_message',
      'type' => 'text_long',
      'locked' => FALSE,
      'cardinality' => '1',
    );
    field_create_field($field);
  }
  if (empty($instances['commerce_line_item'][$type]['commerce_gc_message'])) {
    $instance = array(
      'field_name' => 'commerce_gc_message',
      'entity_type' => 'commerce_line_item',
      'bundle' => $type,
      'label' => t('Message to recipient'),
      'commerce_cart_settings' => array(
        'field_access' => 1,
      ),
    );
    field_create_instance($instance);
  }

  /*
   * Giftcard coupon reference (on giftcard purchase line item)
   */
  if (empty($fields['commerce_giftcards'])) {

    // Create giftcard reference field
    $field = array(
      'settings' => array(
        'target_type' => 'commerce_coupon',
        'handler' => 'base',
        'handler_settings' => array(
          'target_bundles' => array(
            'product_display' => 'giftcard_coupon',
          ),
        ),
      ),
      'field_name' => 'commerce_giftcards',
      'type' => 'entityreference',
      'locked' => TRUE,
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    );
    field_create_field($field);
  }
  if (empty($instances['commerce_line_item'][$type]['commerce_giftcards'])) {
    $instance = array(
      'label' => t('Purchased giftcards'),
      'widget' => array(
        'type' => 'entityreference_autocomplete',
        'weight' => '9',
        'settings' => array(
          'match_operator' => 'CONTAINS',
          'size' => 60,
          'path' => '',
        ),
      ),
      'field_name' => 'commerce_giftcards',
      'entity_type' => 'commerce_line_item',
      'bundle' => $type,
      'default_value' => NULL,
    );
    field_create_instance($instance);
  }
}