You are here

function _commerce_gc_install_helper in Commerce GC 7

Helper function to set up fields

1 call to _commerce_gc_install_helper()
commerce_gc_install in ./commerce_gc.install

File

./commerce_gc.install, line 72
Installs Giftcard transaction table and default fields.

Code

function _commerce_gc_install_helper() {
  field_info_cache_clear();
  $fields = field_info_fields();
  $instances = field_info_instances();

  // Add an inline conditions field.
  _commerce_coupon_install_inline_conditions_field();

  /*
   * Giftcard value
   */
  if (empty($fields['commerce_gc_value'])) {

    // Create max uses field.
    $field = array(
      'field_name' => 'commerce_gc_value',
      'type' => 'commerce_price',
      'locked' => TRUE,
      'cardinality' => '1',
    );
    field_create_field($field);
  }
  if (empty($instances['commerce_coupon']['giftcard_coupon']['commerce_gc_value'])) {
    $instance = array(
      'field_name' => 'commerce_gc_value',
      'entity_type' => 'commerce_coupon',
      'bundle' => 'giftcard_coupon',
      'label' => t('Value'),
      'required' => TRUE,
    );
    field_create_instance($instance);
  }

  /*
   * Giftcard name
   */
  if (empty($fields['commerce_gc_name'])) {

    // Create max uses field.
    $field = array(
      'field_name' => 'commerce_gc_name',
      'type' => 'text',
      'locked' => TRUE,
      'cardinality' => '1',
    );
    field_create_field($field);
  }
  if (empty($instances['commerce_coupon']['giftcard_coupon']['commerce_gc_name'])) {
    $instance = array(
      'field_name' => 'commerce_gc_name',
      'entity_type' => 'commerce_coupon',
      'bundle' => 'giftcard_coupon',
      'label' => t('Name'),
    );
    field_create_instance($instance);
  }
}