convertToBasePrice function added to Core class
This commit is contained in:
parent
1ce5a957f9
commit
01f3cd7324
|
|
@ -319,7 +319,7 @@ class Core
|
|||
/**
|
||||
* Converts price
|
||||
*
|
||||
* @param float $price
|
||||
* @param float $amount
|
||||
* @param string $targetCurrencyCode
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -336,12 +336,38 @@ class Core
|
|||
'target_currency' => $targetCurrency->id,
|
||||
]);
|
||||
|
||||
if (null === $exchangeRate)
|
||||
if (null === $exchangeRate || ! $exchangeRate->rate)
|
||||
return $amount;
|
||||
|
||||
return (float) $amount * $exchangeRate->rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to base price
|
||||
*
|
||||
* @param float $amount
|
||||
* @param string $targetCurrencyCode
|
||||
* @return string
|
||||
*/
|
||||
public function convertToBasePrice($amount, $targetCurrencyCode = null)
|
||||
{
|
||||
$targetCurrency = !$targetCurrencyCode
|
||||
? $this->getCurrentCurrency()
|
||||
: $this->currencyRepository->findOneByField('code', $targetCurrencyCode);
|
||||
|
||||
if (! $targetCurrency)
|
||||
return $amount;
|
||||
|
||||
$exchangeRate = $this->exchangeRateRepository->findOneWhere([
|
||||
'target_currency' => $targetCurrency->id,
|
||||
]);
|
||||
|
||||
if (null === $exchangeRate || ! $exchangeRate->rate)
|
||||
return $amount;
|
||||
|
||||
return (float) $amount / $exchangeRate->rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and convert price with currency symbol
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue