/** * Process the import */ public function process() { /** @var ConfigDataCollection $collection */ $collection = $this->configDataCollectionFactory->create(); $collection->setOrder('path', SortOrder::SORT_ASC); $collection->setOrder('scope', SortOrder::SORT_ASC); $collection->setOrder('scope_id', SortOrder::SORT_ASC); // Filter collection by includes if (null !== $this->include) { $includes = explode(',', $this->include); $orWhere = array(); foreach ($includes as $singlePath) { $singlePath = trim($singlePath); if (!empty($singlePath)) { $orWhere[] = $collection->getConnection()->quoteInto('`path` LIKE ?', $singlePath . '%'); } } if (count($orWhere) > 0) { $collection->getSelect()->where(implode(' OR ', $orWhere)); } } // Filter collection by scope if (null !== $this->includeScope) { $includeScopes = explode(',', $this->includeScope); $orWhere = array(); foreach ($includeScopes as $singlePath) { $singlePath = trim($singlePath); if (!empty($singlePath)) { $orWhere[] = $collection->getConnection()->quoteInto('`scope` like ?', $singlePath); } } if (count($orWhere) > 0) { $collection->getSelect()->where(implode(' OR ', $orWhere)); } } // Filter collection by excludes if (null !== $this->exclude) { $excludes = explode(',', $this->exclude); foreach ($excludes as $singleExclude) { $singleExclude = trim($singleExclude); if (!empty($singleExclude)) { $collection->getSelect()->where('`path` NOT LIKE ?', $singleExclude . '%'); } } } $exportData = []; foreach ($collection as $item) { $data = $item->getData(); unset($data['config_id']); ksort($data); $exportData[] = $data; } if (count($exportData) == 0) { $this->getOutput()->writeln('<error>No export data found.</error>'); return; } $this->writer->write($exportData); }
/** * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function afterSave() { /** @var $collection \Magento\Config\Model\ResourceModel\Config\Data\Collection */ $collection = $this->_configsFactory->create(); $collection->addPathFilter('currency/options'); $values = explode(',', $this->getValue()); $exceptions = []; foreach ($collection as $data) { $match = false; $scopeName = __('Default scope'); if (preg_match('/(base|default)$/', $data->getPath(), $match)) { if (!in_array($data->getValue(), $values)) { $currencyName = $this->_localeCurrency->getCurrency($data->getValue())->getName(); if ($match[1] == 'base') { $fieldName = __('Base currency'); } else { $fieldName = __('Display default currency'); } switch ($data->getScope()) { case ScopeConfigInterface::SCOPE_TYPE_DEFAULT: $scopeName = __('Default scope'); break; case \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE: /** @var $website \Magento\Store\Model\Website */ $website = $this->_websiteFactory->create(); $websiteName = $website->load($data->getScopeId())->getName(); $scopeName = __('website(%1) scope', $websiteName); break; case \Magento\Store\Model\ScopeInterface::SCOPE_STORE: /** @var $store \Magento\Store\Model\Store */ $store = $this->_storeFactory->create(); $storeName = $store->load($data->getScopeId())->getName(); $scopeName = __('store(%1) scope', $storeName); break; } $exceptions[] = __('Currency "%1" is used as %2 in %3.', $currencyName, $fieldName, $scopeName); } } } if ($exceptions) { throw new \Magento\Framework\Exception\LocalizedException(__(join("\n", $exceptions))); } return parent::afterSave(); }