public function ProductBundleItem::setVariations in Commerce Product Bundle 8
Sets the variations.
If the bundle item doesn't hold a product reference yet, the product of the first variation will be set as the bundle items product.
Parameters
\Drupal\commerce_product\Entity\ProductVariationInterface[] $variations: The variations.
Return value
\Drupal\commerce_product_bundle\Entity\BundleItemInterface The called product bundle item entity.
Throws
\InvalidArgumentException In case the variations don't belong to the same product or if applicable to the already referenced product.
Overrides BundleItemInterface::setVariations
File
- src/
Entity/ ProductBundleItem.php, line 430
Class
- ProductBundleItem
- Defines the product bundle item entity.
Namespace
Drupal\commerce_product_bundle\EntityCode
public function setVariations(array $variations) {
if (empty($variations)) {
return $this;
}
// If there is no product referenced on the bundle item, do it now.
if ($this
->get('product')
->isEmpty()) {
$this
->setProduct($variations[0]
->getProduct());
}
$this
->assertSameProduct($variations);
$this
->set('variations', $variations);
return $this;
}