You are here

function uc_discounts_get_product_ids_for_discount_id in Ubercart Discounts (Alternative) 7.2

Returns product IDs to which a discount ID applies.

Note: this function does not check filter_type so a discount with filter_type other than UC_DISCOUNTS_FILTER_TYPE_PRODUCTS will return no values.

Parameters

int $discount_id:

const $grouping:

bool $exclude_all_products:

Return value

array Array of product IDs (node IDs)

3 calls to uc_discounts_get_product_ids_for_discount_id()
uc_discounts_admin_discount_copy_form in uc_discounts/uc_discounts.admin.inc
Generates admin form to create a copy of existing discount.
uc_discounts_get_product_ids_for_discount in uc_discounts/uc_discounts.module
Returns product IDs to which a discount applies.
_uc_discounts_product_filter_form in uc_discounts/uc_discounts.admin.inc
Helper function that creates a series of dropdowns for selecting a product via product_id, sku, class, term, or author.

File

uc_discounts/uc_discounts.module, line 1013

Code

function uc_discounts_get_product_ids_for_discount_id($discount_id, $grouping, $exclude_all_products = FALSE) {
  $query = "SELECT product_id\n            FROM {uc_discounts_products}\n            WHERE discount_id = :discount_id\n            AND grouping = :grouping";
  $args = array(
    ':discount_id' => $discount_id,
    ':grouping' => $grouping,
  );
  if ($exclude_all_products) {
    $query .= ' AND product_id <> :product_id';
    $args[':product_id'] = UC_DISCOUNTS_OPTION_ALL_PRODUCTS;
  }
  $result = db_query($query, $args);
  $ids = array();
  foreach ($result as $row) {
    $ids[] = $row->product_id;
  }
  return $ids;
}