You are here

public function CommerceCurrencyResolverAmountTrait::getPrice in Commerce Currency Resolver 8

Get price based on currency price and target currency.

Parameters

\Drupal\commerce_price\Price $input_price: Default price added in condition, offer, etc.

Return value

\Drupal\commerce_price\Price Return Price object.

3 calls to CommerceCurrencyResolverAmountTrait::getPrice()
OrderFixedAmountOff::apply in src/Plugin/Commerce/PromotionOffer/OrderFixedAmountOff.php
Applies the offer to the given entity.
OrderItemFixedAmountOff::apply in src/Plugin/Commerce/PromotionOffer/OrderItemFixedAmountOff.php
Applies the offer to the given entity.
OrderTotalPrice::evaluate in src/Plugin/Commerce/Condition/OrderTotalPrice.php
Evaluates the condition.

File

src/Plugin/Commerce/CommerceCurrencyResolverAmountTrait.php, line 90

Class

CommerceCurrencyResolverAmountTrait
Provides common configuration for fixed amount off offers.

Namespace

Drupal\commerce_currency_resolver\Plugin\Commerce

Code

public function getPrice(Price $input_price) {
  $target_currency = $this
    ->currentCurrency();

  // If we have specified price listed.
  if (isset($this->configuration['fields'][$target_currency])) {
    $priceField = $this->configuration['fields'][$target_currency];

    // Added check if prices is empty
    // (etc. after migration of old discounts).
    if (!empty($priceField['number'])) {
      return new Price($priceField['number'], $priceField['currency_code']);
    }
  }

  // Auto-calculate if we don't have any price in currency field.
  return \Drupal::service('commerce_currency_resolver.calculator')
    ->priceConversion($input_price, $target_currency);
}