You are here

function _productfield_products in Commerce Webform 7.2

Get a list of commerce products avaiable for selection.

Parameters

array $component: Webform productfield component

Return value

array An array of commerce_product objects available for selection with this component.

4 calls to _productfield_products()
commerce_webform_update_webform_submission_productfield in ./commerce_webform.module
Update the details stored on a webform submission product field.
_webform_csv_data_productfield in ./productfield.inc
Implements _webform_csv_data_component().
_webform_csv_headers_productfield in ./productfield.inc
Implements _webform_csv_headers_component().
_webform_table_productfield in ./productfield.inc
Implements _webform_table_component().

File

./productfield.inc, line 1181

Code

function _productfield_products($component) {
  $items = isset($component['extra']['items']) ? $component['extra']['items'] : array();
  $product_type = $component['extra']['product_type'];
  $product_ids = array();
  if (empty($product_type)) {

    // Build an array of product IDs from this field's values.
    foreach ($items as $item) {
      $product_ids[] = $item['product_id'];
    }
  }
  else {
    $query = new EntityFieldQuery();
    $result = $query
      ->entityCondition('entity_type', 'commerce_product')
      ->entityCondition('bundle', $product_type)
      ->execute();
    if (!empty($result['commerce_product'])) {
      $product_ids = array_keys($result['commerce_product']);
    }
  }
  return commerce_product_load_multiple($product_ids);
}