/**
  * Adds new rate or updates existing one
  *
  * @param string $currencyFrom
  * @param string $currencyTo
  * @param float  $rate
  */
 protected function addUpdateExchangeRate($currencyFrom, $currencyTo, $rate)
 {
     if (!in_array($currencyTo, $this->managedCurrencies)) {
         return false;
     }
     $exchangeRate = $this->ratesRepository->findOneBy(['currencyFrom' => $currencyFrom, 'currencyTo' => $currencyTo]);
     if (null === $exchangeRate) {
         $exchangeRate = new CurrencyRate();
         $exchangeRate->setCurrencyFrom($currencyFrom);
         $exchangeRate->setCurrencyTo($currencyTo);
         $exchangeRate->setExchangeRate($rate);
         $this->helper->getEntityManager()->persist($exchangeRate);
     } else {
         $exchangeRate->setExchangeRate($rate);
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Sets exchange rate for target and base currency pair
  *
  * @param CurrencyRate $rate
  * @param string       $targetCurrency
  */
 protected function setExchangeRate(CurrencyRate $rate, $targetCurrency)
 {
     $this->exchangeRates[$targetCurrency][$rate->getCurrencyFrom()] = $rate->getExchangeRate();
 }
Ejemplo n.º 3
0
 /**
  * @return \WellCommerce\Bundle\IntlBundle\Entity\CurrencyRateInterface
  */
 public function create()
 {
     $currencyRate = new CurrencyRate();
     $currencyRate->setExchangeRate(1);
     return $currencyRate;
 }