Esempio n. 1
0
 /**
  * Loads Currency from session or repository
  *
  * @return CurrencyInterface Instance of Customer loaded
  *
  * @throws CurrencyNotAvailableException Any currency available
  */
 public function loadCurrency()
 {
     if ($this->currency instanceof CurrencyInterface) {
         return $this->currency;
     }
     $currencyIdInSession = $this->currencySessionManager->get();
     /**
      * Tries to load currency saved in session
      */
     if ($currencyIdInSession) {
         $this->currency = $this->currencyRepository->find($currencyIdInSession);
     }
     if ($this->currency instanceof CurrencyInterface) {
         return $this->currency;
     }
     /**
      * Otherwise, tries to load default currency. Notice that default
      * currency is defined as parameter
      */
     $this->currency = $this->currencyRepository->findOneBy(['iso' => $this->defaultCurrencyIsoCode]);
     if ($this->currency instanceof CurrencyInterface) {
         $this->currencySessionManager->set($this->currency);
         return $this->currency;
     }
     throw new CurrencyNotAvailableException();
 }
Esempio n. 2
0
 /**
  * Save currency to session
  *
  * @param CurrencyInterface $currency Currency
  *
  * @return $this Self object
  */
 private function saveCurrencyToSession(CurrencyInterface $currency)
 {
     $this->currencySessionManager->set($currency);
     return $this;
 }