You are here

function commerce_node_checkout_install in Commerce Node Checkout 7

Implements hook_install().

File

./commerce_node_checkout.install, line 10
Provides install, update, schema and uninstall hooks for the module

Code

function commerce_node_checkout_install() {
  $t = get_t();

  // Create the node checkout product type - we do this for the
  // commerce_node_checkout_expiry sub-module to be able to target the product
  // with additional product types.
  $product_types = commerce_product_types();
  if (empty($product_types['commerce_node_checkout'])) {
    $product_type = commerce_product_ui_product_type_new();
    $product_type['type'] = 'commerce_node_checkout';
    $product_type['name'] = $t('Pay to publish');
    $product_type['description'] = $t('A product associated with publishing a node.');
    $product_type['is_new'] = TRUE;
    commerce_product_ui_product_type_save($product_type, FALSE);
    commerce_price_create_instance('commerce_price', 'commerce_product', 'commerce_node_checkout', $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('entityreference')) {
    field_cache_clear();
  }

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

  // Setup line item type.
  commerce_line_item_configure_line_item_type(array(
    'type' => 'commerce_node_checkout',
  ));
  commerce_product_line_item_configuration(array(
    'type' => 'commerce_node_checkout',
  ));

  // Create our fields.
  foreach (_commerce_node_checkout_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_node_checkout_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);
    }
  }
}