You are here

public function PriceListDefaultBasePriceResolver::getPrice in Commerce Pricelist 8

Parameters

\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.

Return value

\Drupal\commerce_price\Price The purchasable price.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException

File

src/Resolver/PriceListDefaultBasePriceResolver.php, line 48

Class

PriceListDefaultBasePriceResolver
Class PriceListDefaultBasePriceResolver.

Namespace

Drupal\commerce_pricelist\Resolver

Code

public function getPrice(PurchasableEntityInterface $entity) {
  $type_id = $entity
    ->getEntityType()
    ->id();
  $currency_code = \Drupal::service('commerce_store.current_store')
    ->getStore()
    ->getDefaultCurrencyCode();
  $price = new Price('0.00', $currency_code);
  if ($type_id == 'commerce_product_bundle') {
    if (!$entity
      ->get('bundle_price')
      ->isEmpty() && !$entity
      ->get('bundle_price')
      ->first()
      ->toPrice()
      ->isZero()) {
      $price = $entity
        ->get('bundle_price')
        ->first()
        ->toPrice();
    }
  }
  else {
    if (!$entity
      ->getPrice()
      ->isZero()) {
      $price = $entity
        ->getPrice();
    }
  }
  return $price;
}