You are here

function commerce_coupon_commerce_price_component_type_info in Commerce Coupon 7

Implements hook_commerce_price_component_type_info().

Creates a new price component for each coupon type.

File

./commerce_coupon.module, line 852
Coupon System for Drupal Commerce.

Code

function commerce_coupon_commerce_price_component_type_info() {
  $components = array();
  $coupons = commerce_coupon_load_multiple(array(), array(
    'is_active' => TRUE,
  ));

  // Add a price component type per each coupon.
  foreach ($coupons as $coupon) {
    $name = commerce_coupon_type_get_name($coupon->type);
    $coupon_machine_name = commerce_coupon_machine_name_code($coupon);
    $components[$coupon->type . '_' . $coupon_machine_name] = array(
      'title' => $name,
      'display_title' => $name,
      'coupon_type' => $coupon->type,
      'coupon_code' => $coupon_machine_name,
    );
  }
  return $components;
}