You are here

public function ProductBundleItem::getUnitPrice in Commerce Product Bundle 8

Gets the price of one unit of the referenced product variations.

Return value

\Drupal\commerce_price\Price|null The unit price or NULL.

Overrides BundleItemInterface::getUnitPrice

File

src/Entity/ProductBundleItem.php, line 202

Class

ProductBundleItem
Defines the product bundle item entity.

Namespace

Drupal\commerce_product_bundle\Entity

Code

public function getUnitPrice() {
  if (!$this
    ->get('unit_price')
    ->isEmpty()) {
    return $this
      ->get('unit_price')
      ->first()
      ->toPrice();
  }
  $variation = $this
    ->getCurrentVariation();
  return $variation ? $variation
    ->getPrice() : NULL;
}