public function FormattedPrice::getValue in Commerce Core 8.2
Gets the data value.
Return value
mixed The data value.
Overrides PrimitiveBase::getValue
File
- modules/
price/ src/ Plugin/ DataType/ FormattedPrice.php, line 21
Class
- FormattedPrice
- Defines a data type for formatted prices.
Namespace
Drupal\commerce_price\Plugin\DataTypeCode
public function getValue() {
$parent = $this
->getParent();
assert($parent instanceof PriceItem);
$formatted_price = NULL;
if (!$parent
->isEmpty()) {
try {
$price = $parent
->toPrice();
$currency_formatter = \Drupal::service('commerce_price.currency_formatter');
$formatted_price = $currency_formatter
->format($price
->getNumber(), $price
->getCurrencyCode());
} catch (\InvalidArgumentException $exception) {
}
}
return $formatted_price;
}