You are here

public function ProductBundleItem::setProduct in Commerce Product Bundle 8

@inheritdoc

Overrides BundleItemInterface::setProduct

1 call to ProductBundleItem::setProduct()
ProductBundleItem::setVariations in src/Entity/ProductBundleItem.php
Sets the variations.

File

src/Entity/ProductBundleItem.php, line 293

Class

ProductBundleItem
Defines the product bundle item entity.

Namespace

Drupal\commerce_product_bundle\Entity

Code

public function setProduct(ProductInterface $product) {

  // Unset variations, if we get another product.
  if ($this
    ->hasProduct()) {
    $currentProductId = $this
      ->getProduct()
      ->id();
    $newProductId = $product
      ->id();
    if ($currentProductId !== $newProductId) {
      $this
        ->set('variations', NULL);
    }
  }
  $this
    ->set('product', $product);
  return $this;
}