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
 /**
  * Load currency from session
  *
  * @return CurrencyInterface|null Currency
  *
  * @throws CurrencyNotAvailableException No currency available
  */
 private function loadCurrencyFromSession()
 {
     $currencyIdInSession = $this->currencySessionManager->get();
     return $currencyIdInSession ? $this->currency = $this->currencyRepository->find($currencyIdInSession) : null;
 }