Exemplo n.º 1
0
 /**
  * Check base currency is available in installed currencies
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function afterSave()
 {
     $value = $this->getValue();
     if (!in_array($value, $this->_getInstalledCurrencies())) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, we haven\'t installed the base currency you selected.'));
     }
     $this->currencyFactory->create()->saveRates([$value => [$value => 1]]);
     return parent::afterSave();
 }
 /**
  * Check default currency is available in installed currencies
  * Check default currency is available in allowed currencies
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function afterSave()
 {
     if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, we haven\'t installed the default display currency you selected.'));
     }
     if (!in_array($this->getValue(), $this->_getAllowedCurrencies())) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, the default display currency you selected is not available in allowed currencies.'));
     }
     return parent::afterSave();
 }
Exemplo n.º 3
0
 /**
  * Check is isset default display currency in allowed currencies
  * Check allowed currencies is available in installed currencies
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function afterSave()
 {
     $exceptions = [];
     foreach ($this->_getAllowedCurrencies() as $currencyCode) {
         if (!in_array($currencyCode, $this->_getInstalledCurrencies())) {
             $exceptions[] = __('Selected allowed currency "%1" is not available in installed currencies.', $this->_localeCurrency->getCurrency($currencyCode)->getName());
         }
     }
     if (!in_array($this->_getCurrencyDefault(), $this->_getAllowedCurrencies())) {
         $exceptions[] = __('Default display currency "%1" is not available in allowed currencies.', $this->_localeCurrency->getCurrency($this->_getCurrencyDefault())->getName());
     }
     if ($exceptions) {
         throw new \Magento\Framework\Exception\LocalizedException(__(join("\n", $exceptions)));
     }
     return parent::afterSave();
 }
Exemplo n.º 4
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
  * @param \Magento\Framework\Model\ModelResource\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Framework\Model\ModelResource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $config, $scopeConfig, $resource, $resourceCollection, $data);
     $this->currencyFactory = $currencyFactory;
 }
Exemplo n.º 5
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Framework\Locale\CurrencyInterface $localeCurrency
  * @param \Magento\Framework\Model\Resource\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\Db $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Locale\CurrencyInterface $localeCurrency, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = [])
 {
     $this->_localeCurrency = $localeCurrency;
     parent::__construct($context, $registry, $config, $scopeConfig, $resource, $resourceCollection, $data);
 }