You are here

function commerce_discount_inline_conditions_build_alter in Commerce Discount 7

Implements hook_inline_conditions_build_alter().

File

./commerce_discount.inline_conditions.inc, line 117
Provides Inline Conditions integration for the Commerce Discount module.

Code

function commerce_discount_inline_conditions_build_alter(&$value) {
  switch ($value['condition_name']) {
    case 'commerce_order_contains_products':
    case 'commerce_order_has_specific_quantity_products':
      if (!empty($value['condition_settings']['products'])) {
        $entity_ids = array();
        foreach ($value['condition_settings']['products'] as $delta) {
          $entity_ids[] = reset($delta);
        }
        $products = commerce_product_load_multiple($entity_ids);
        $value['condition_settings']['products'] = '';
        foreach ($products as $product) {
          $value['condition_settings']['products'] .= $product->sku;
          if ($product !== end($products)) {
            $value['condition_settings']['products'] .= ', ';
          }
        }
      }
      break;
    case 'commerce_product_has_specified_terms':
      $terms = $value['condition_settings']['terms'];
      $value['condition_settings']['terms'] = '';
      foreach ($terms as $term) {
        $value['condition_settings']['terms'] .= reset($term);
        if ($term !== end($terms)) {
          $value['condition_settings']['terms'] .= ', ';
        }
      }
      break;
    case 'commerce_product_contains_products':
      $entity_ids = array();
      foreach ($value['condition_settings']['sku'] as $delta) {
        $entity_ids[] = reset($delta);
      }
      $products = commerce_product_load_multiple($entity_ids);
      $value['condition_settings']['sku'] = '';
      foreach ($products as $product) {
        $value['condition_settings']['sku'] .= $product->sku;
        if ($product !== end($products)) {
          $value['condition_settings']['sku'] .= ', ';
        }
      }
      break;
  }
}