You are here

function commerce_recurring_install in Commerce Recurring Framework 7

Same name and namespace in other branches
  1. 7.2 commerce_recurring.install \commerce_recurring_install()

Implements hook_install().

File

./commerce_recurring.install, line 39

Code

function commerce_recurring_install() {

  // Create the recurring product type.
  $product_type = commerce_product_ui_product_type_new();
  $product_type['type'] = 'recurring';
  $product_type['name'] = t('Recurring product');
  $product_type['description'] = t('A recurring purchase product type.');
  $product_type['is_new'] = TRUE;
  commerce_product_ui_product_type_save($product_type, FALSE);
  commerce_price_create_instance('commerce_price', 'commerce_product', 'recurring', t('Price'), 0, 'calculated_sell_price');

  // If a field type we know should exist isn't found, clear the Field cache.
  if (!field_info_field_types('commerce_order_reference') || !field_info_field_types('interval') || !field_info_field_types('datestamp')) {
    field_cache_clear();
  }

  // Make sure our entity info exists
  entity_info_cache_clear();

  // Create our fields
  foreach (_commerce_recurring_installed_fields() as $field_name => $field_detail) {

    // Look for existing field.
    $field = field_info_field($field_name);
    if (empty($field)) {
      $field = field_create_field($field_detail);
    }
  }

  // And their instances
  foreach (_commerce_recurring_installed_instances() as $field_name => $instance_detail) {

    // Look for existing instance.
    $instance = field_info_instance($instance_detail['entity_type'], $field_name, $instance_detail['bundle']);
    if (empty($instance)) {
      field_create_instance($instance_detail);
    }
  }

  // Setup our order type
  commerce_order_configure_order_type('recurring_order');
}