You are here

public function BulkVariationsCreator::getAttributesCombinations in Commerce Bulk 8

Gets all ids combinations of the commerce_product's attribute fields.

Parameters

array $variations: The commerce product variations.

array $return: (optional) Whether to return all attributes combinations or just ~ 500.

Return value

array|null 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.
  • "not_all": The maximum number of combinations to return.

Overrides BulkVariationsCreatorInterface::getAttributesCombinations

4 calls to BulkVariationsCreator::getAttributesCombinations()
BulkVariationsCreator::createAllIefFormVariations in src/BulkVariationsCreator.php
An AJAX callback to create all possible variations.
BulkVariationsCreator::createAllProductVariations in src/BulkVariationsCreator.php
Creates all possible variations for commerce_product.
BulkVariationsCreator::createProductVariation in src/BulkVariationsCreator.php
Creates a variation for commerce_product.
BulkVariationsCreator::getDuplicationsHtmlList in src/BulkVariationsCreator.php
Gets duplicated variations HTML list.

File

src/BulkVariationsCreator.php, line 379

Class

BulkVariationsCreator
Default implementation of the BulkVariationsCreatorInterface.

Namespace

Drupal\commerce_bulk

Code

public function getAttributesCombinations(array $variations, array $return = [
  'not_all' => TRUE,
]) {
  $all = $this
    ->getUsedAttributesCombinations($variations);

  // Restrict by default the number of returned not used combinations if their
  // number exceeds some resonable number (500). To get all possible
  // combinations call this method with an empty array as the second argument.
  if (!empty($return['not_all'])) {
    if ($return['not_all'] === TRUE) {
      $return['not_all'] = static::getSkuSettings($all['last_variation'])['maximum'] - 2;
    }
    if ($all['count'] > $return['not_all']) {
      $all += $return;
      $all['used_combinations']['not_all'] = $return['not_all'];
    }
  }
  $all['not_used_combinations'] = $this
    ->getArrayValueCombinations($all['attributes']['ids'], $all['used_combinations']);
  unset($all['used_combinations']['not_all']);
  $all['not_used'] = count($all['not_used_combinations']);
  return $all;
}