You are here

public static function ProductBundleItemInlineForm::variationsOptions in Commerce Product Bundle 8

Get variations select options which belong to a product.

Parameters

int $productId: Product entity id.

Return value

array Selection array.

2 calls to ProductBundleItemInlineForm::variationsOptions()
ProductBundleItemInlineForm::entityForm in src/Form/ProductBundleItemInlineForm.php
Builds the entity form.
ProductBundleItemInlineForm::variationsRefresh in src/Form/ProductBundleItemInlineForm.php
Product field ajax callback.

File

src/Form/ProductBundleItemInlineForm.php, line 123

Class

ProductBundleItemInlineForm
Defines the inline form for product bundle items.

Namespace

Drupal\commerce_product_bundle\Form

Code

public static function variationsOptions($productId) {
  $values['_none'] = '- ' . \Drupal::translation()
    ->translate('All') . ' -';
  $product = Product::load($productId);
  $variations = $product
    ->getVariations();

  /** @var \Drupal\commerce_product\Entity\ProductVariation $variation */
  foreach ($variations as $variation) {
    $values[$variation
      ->id()] = $variation
      ->id() . ': ' . $variation
      ->getTitle();
  }
  return $values;
}