You are here

protected function Price::assertSameCurrency in Commerce Core 8.2

Asserts that the two prices have the same currency.

Parameters

\Drupal\commerce_price\Price $first_price: The first price.

\Drupal\commerce_price\Price $second_price: The second price.

Throws

\Drupal\commerce_price\Exception\CurrencyMismatchException Thrown when the prices do not have the same currency.

3 calls to Price::assertSameCurrency()
Price::add in modules/price/src/Price.php
Adds the given price to the current price.
Price::compareTo in modules/price/src/Price.php
Compares the current price with the given price.
Price::subtract in modules/price/src/Price.php
Subtracts the given price from the current price.

File

modules/price/src/Price.php, line 314

Class

Price
Provides a value object for monetary values.

Namespace

Drupal\commerce_price

Code

protected function assertSameCurrency(Price $first_price, Price $second_price) {
  if ($first_price
    ->getCurrencyCode() != $second_price
    ->getCurrencyCode()) {
    throw new CurrencyMismatchException(sprintf('The provided prices have mismatched currencies: %s, %s.', $first_price
      ->__toString(), $second_price
      ->__toString()));
  }
}