You are here

public function PriceListItem::label in Commerce Pricelist 8.2

Gets the label of the entity.

Return value

string|null The label of the entity, or NULL if there is no label defined.

Overrides ContentEntityBase::label

File

src/Entity/PriceListItem.php, line 88

Class

PriceListItem
Defines the price list item entity.

Namespace

Drupal\commerce_pricelist\Entity

Code

public function label() {
  if ($this
    ->isNew()) {
    return '';
  }
  $purchasable_entity_label = $this
    ->getPurchasableEntity()
    ->label();
  $currency_formatter = \Drupal::service('commerce_price.currency_formatter');
  $price = $this
    ->getPrice();
  $formatted_price = $currency_formatter
    ->format($price
    ->getNumber(), $price
    ->getCurrencyCode());
  return sprintf('%s: %s', $purchasable_entity_label, $formatted_price);
}