public function testFindCurrencyByIso()
 {
     $data = [['name' => 'US Dollar', 'iso_code' => 'USD', 'convert_nominal' => 1, 'convert_rate' => 80, 'sort_order' => 1, 'format_string' => '$ #', 'thousands_sep' => '.', 'dec_point' => ',', 'is_main' => 0, 'intl_formatting' => 1], 'Euro' => ['name' => 'Euro', 'iso_code' => 'EUR', 'convert_rate' => 90, 'format_string' => '€ #', 'is_main' => 1]];
     $storage = (new Currency())->getStorage();
     FunctionalHelper::flushStorage($storage);
     $this->assertFileNotExists($storage);
     CurrencyStorageHelper::generateStorage($data, $storage, Currency::className());
     $c = CurrencyHelper::findCurrencyByIso('USD');
     $this->assertEquals('US Dollar', $c->name);
     return $c;
 }
 public function actionChange()
 {
     $isoCode = Yii::$app->request->post('isoCode');
     if ($isoCode === null) {
         throw new BadRequestHttpException();
     }
     $newUserCurrency = CurrencyHelper::findCurrencyByIso($isoCode);
     if ($newUserCurrency !== null) {
         $oldUserCurrency = CurrencyHelper::getUserCurrency();
         CurrencyHelper::setUserCurrency($newUserCurrency);
         $event = new AfterUserCurrencyChangeEvent();
         $event->oldUserCurrency = $oldUserCurrency;
         $event->newUserCurrency = $newUserCurrency;
         CurrenciesModule::module()->trigger(CurrenciesModule::AFTER_USER_CURRENCY_CHANGE, $event);
     }
     return $this->redirect(Yii::$app->request->referrer);
 }
 /**
  * Get a user currency from session
  * @return Currency
  */
 public static function getUserCurrency()
 {
     if (static::$userCurrency === null) {
         $isoCode = Yii::$app->session->get(CurrenciesModule::CURRENCY_SESSION_KEY);
         $userCurrency = CurrencyHelper::findCurrencyByIso($isoCode);
         static::$userCurrency = $userCurrency !== null ? $userCurrency : static::getMainCurrency();
     }
     return static::$userCurrency;
 }