You are here

function commerce_bpc_get_combinations in Commerce Bulk Product Creation 7

Same name and namespace in other branches
  1. 7.2 commerce_bpc.module \commerce_bpc_get_combinations()

Build combinations from a submitted form.

Parameters

array $form: The form structure of the bulk creation form, after it has been altered by the bulk creation hooks.

array $form_state: The form state after form submission. Modules that have altered the form through the bulk creation hooks will have recorded what they did in $form_state['commerce_bpc'][MODULE_NAME].

Return value

array An array describing the combinations.

2 calls to commerce_bpc_get_combinations()
commerce_bpc_create_bulk_form_create_products_submit in ./commerce_bpc.forms.inc
Form submission handler for commerce_bpc_create_bulk_form().
commerce_bpc_create_bulk_form_validate in ./commerce_bpc.forms.inc
Form validation hanlder for for commerce_bpc_create_bulk_form().

File

./commerce_bpc.module, line 380

Code

function commerce_bpc_get_combinations($form, &$form_state) {

  // We need the cartesian product of the arrays in $options.
  // In order to do that, we loop through these arrays, at every
  // stage taking the cartesian product of the actual array with
  // what is there already. So after the first iteration,
  // $combinations will just be the first member of $options.
  // After the second, it will be the product of this with the
  // second member, after the third, we will have the product
  // of the previous product with the third member, and so on.
  //
  // Initialize with an empty array as sole member, so that the first
  // iteration has something to work with.
  $combinations = array(
    array(),
  );
  $hook = 'commerce_bpc_get_combinations';
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    $function($form, $form_state, $combinations);
  }
  return $combinations;
}