You are here

protected function ProductBundleItem::assertSameProduct in Commerce Product Bundle 8

Ensure that all passed variations belong to the same product.

Parameters

array $variations: \Drupal\commerce_product\Entity\ProductVariationInterface[].

Throws

\InvalidArgumentException In case a variation belongs to another product.

3 calls to ProductBundleItem::assertSameProduct()
ProductBundleItem::addVariation in src/Entity/ProductBundleItem.php
Adds a variation.
ProductBundleItem::setCurrentVariation in src/Entity/ProductBundleItem.php
Gets the currently selected variation, or the default variation.
ProductBundleItem::setVariations in src/Entity/ProductBundleItem.php
Sets the variations.

File

src/Entity/ProductBundleItem.php, line 454

Class

ProductBundleItem
Defines the product bundle item entity.

Namespace

Drupal\commerce_product_bundle\Entity

Code

protected function assertSameProduct(array $variations) {
  foreach ($variations as $variation) {
    $shouldBeOfType = $this
      ->getProduct()
      ->id();
    $isType = $variation
      ->getProductId();
    if ($shouldBeOfType !== $isType) {
      throw new \InvalidArgumentException('All variations of a bundle item must be from the same product.');
    }
  }
}