You are here

function commerce_discount_uninstall in Commerce Discount 7

Implements hook_uninstall().

Each implementing module adding a bundle needs to take care of deleting it, upon uninstall.

See also

commerce_discount_type_info()

commerce_discount_offer_type_info()

File

./commerce_discount.install, line 730
Install, update, and uninstall functions for the commerce discount module.

Code

function commerce_discount_uninstall() {
  module_load_include('module', 'commerce');

  // Drop all bundles attached on commerce_discount and commerce_discount_offer
  // entity types.
  field_attach_delete_bundle('commerce_discount', 'order_discount');
  field_attach_delete_bundle('commerce_discount', 'product_discount');
  field_attach_delete_bundle('commerce_discount_offer', 'fixed_amount');
  field_attach_delete_bundle('commerce_discount_offer', 'percentage');
  field_attach_delete_bundle('commerce_discount_offer', 'free_shipping');
  field_attach_delete_bundle('commerce_discount_offer', 'commerce_percent_off_shipping');
  field_attach_delete_bundle('commerce_discount_offer', 'commerce_percent_off_ship_serv');
  field_attach_delete_bundle('commerce_discount_offer', 'free_products');

  // Delete custom line items types.
  field_attach_delete_bundle('commerce_line_item', 'commerce_discount');
  field_attach_delete_bundle('commerce_line_item', 'product_discount');

  // Then delete the related fields.
  commerce_delete_field('commerce_discount_offer');
  commerce_delete_field('commerce_fixed_amount');
  commerce_delete_field('commerce_percentage');
  commerce_delete_field('commerce_discounts');
  commerce_delete_field('inline_conditions');
  commerce_delete_field('commerce_free_shipping');
  commerce_delete_field('commerce_percent_off_shipping');
  commerce_delete_field('commerce_percent_off_ship_serv');
  commerce_delete_field('commerce_free_products');
  commerce_delete_field('commerce_discount_date');
  commerce_delete_field('discount_usage_per_person');
  commerce_delete_field('discount_usage_limit');

  // Delete all rules added by commerce_discount module.
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'rules_config')
    ->propertyCondition('module', 'commerce_discount')
    ->execute();
  if (!empty($result)) {
    rules_config_delete(array_keys(reset($result)));
  }

  // Delete variable settings.
  variable_del('commerce_discount_line_item_types');
}