Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Base.php
Go to the documentation of this file.
1 <?php
12 
17 class Base extends AbstractCurrency
18 {
22  private $currencyFactory;
23 
34  public function __construct(
35  \Magento\Framework\Model\Context $context,
36  \Magento\Framework\Registry $registry,
38  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
39  \Magento\Directory\Model\CurrencyFactory $currencyFactory,
40  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
41  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
42  array $data = []
43  ) {
44  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
45  $this->currencyFactory = $currencyFactory;
46  }
47 
54  public function afterSave()
55  {
56  $value = $this->getValue();
57  if (!in_array($value, $this->_getInstalledCurrencies())) {
58  throw new \Magento\Framework\Exception\LocalizedException(
59  __('Sorry, we haven\'t installed the base currency you selected.')
60  );
61  }
62 
63  $this->currencyFactory->create()->saveRates([$value =>[$value => 1]]);
64  return parent::afterSave();
65  }
66 }
$config
Definition: fraud_order.php:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Base.php:34