You are here

public function BulkVariationsCreator::getArrayValueCombinations in Commerce Bulk 8

Gets combinations of an Array values.

See the function source origin .

Parameters

array $data: An array with mixed data.

array $exclude: (optional) An array with mixed data to exclude from the return.

array $all: An array of used combinations, not used combinations and their number, last variation, variation attributes ids and options:

  • "last_variation": The variation on the last inline entity form array.
  • "used_combinations": The already used combinations.
  • "not_used_combinations": Yet not used combinations.
  • "count": The number of all combinations.
  • "attributes": An array with attributes ids and options:
    • "ids": The array of field_name => id pairs.
    • "options": The array of id => field_label pairs.
  • "duplicated": The number of duplicated combinations.
  • "used": The number of used combinations. combinations.

array $group: An array with mixed data.

null|string|array $value: A proxy value.

int $i: A counter.

null|string $k: A proxy array key.

null|int $c: A proxy counter.

null|string $f: A field name.

Return value

array An array of all commerce product variations' combinations.

Overrides BulkVariationsCreatorInterface::getArrayValueCombinations

1 call to BulkVariationsCreator::getArrayValueCombinations()
BulkVariationsCreator::getAttributesCombinations in src/BulkVariationsCreator.php
Gets all ids combinations of the commerce_product's attribute fields.

File

src/BulkVariationsCreator.php, line 403

Class

BulkVariationsCreator
Default implementation of the BulkVariationsCreatorInterface.

Namespace

Drupal\commerce_bulk

Code

public function getArrayValueCombinations(array $data = [], array $exclude = [], array &$all = [], array $group = [], $value = NULL, $i = 0, $k = NULL, $c = NULL, $f = NULL) {
  $keys = $k ?: array_keys($data);
  $count = $c ?: count($data);
  if ($include = isset($value) === TRUE) {
    $group[$f] = $value;
  }
  if ($i >= $count && $include) {
    foreach ($exclude as $index => $combination) {
      if ($group == $combination) {
        unset($exclude[$index]);
        $include = FALSE;
        break;
      }
    }
    if ($include) {
      $all[] = $group;
    }
  }
  elseif (isset($keys[$i])) {
    if (isset($exclude['not_all']) && !empty($all) && count($all) > $exclude['not_all']) {
      return $all;
    }
    $field_name = $keys[$i];
    foreach ($data[$field_name] as $val) {
      $this
        ->getArrayValueCombinations($data, $exclude, $all, $group, $val, $i + 1, $keys, $count, $field_name);
    }
  }
  return $all;
}