/** * Read configuration by code * * @param null|string $code * @return array * @throws NoSuchEntityException */ public function read($code = null) { $store = $this->_storeManager->getStore($code); $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $store->getWebsite()->getCode())->getSource(); $config = array_replace_recursive($websiteConfig, $this->_initialConfig->getData("stores|{$code}")); $collection = $this->_collectionFactory->create(['scope' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scopeId' => $store->getId()]); $dbStoreConfig = []; foreach ($collection as $item) { $dbStoreConfig[$item->getPath()] = $item->getValue(); } return $this->_converter->convert($dbStoreConfig, $config); }
/** * Read configuration by code * * @param string $code * @return array */ public function read($code = null) { $config = array_replace_recursive($this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT)->getSource(), $this->_initialConfig->getData("websites|{$code}")); $website = $this->_websiteFactory->create(); $website->load($code); $collection = $this->_collectionFactory->create(['scope' => \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES, 'scopeId' => $website->getId()]); $dbWebsiteConfig = []; foreach ($collection as $configValue) { $dbWebsiteConfig[$configValue->getPath()] = $configValue->getValue(); } $dbWebsiteConfig = $this->_converter->convert($dbWebsiteConfig); if (count($dbWebsiteConfig)) { $config = array_replace_recursive($config, $dbWebsiteConfig); } return $config; }
/** * Read configuration data * * @param null|string $scope * @throws LocalizedException Exception is thrown when scope other than default is given * @return array */ public function read($scope = null) { $scope = $scope === null ? ScopeConfigInterface::SCOPE_TYPE_DEFAULT : $scope; if ($scope !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT) { throw new \Magento\Framework\Exception\LocalizedException(__("Only default scope allowed")); } $config = $this->_initialConfig->getData($scope); $collection = $this->_collectionFactory->create(['scope' => $scope]); $dbDefaultConfig = []; foreach ($collection as $item) { $dbDefaultConfig[$item->getPath()] = $item->getValue(); } $dbDefaultConfig = $this->_converter->convert($dbDefaultConfig); $config = array_replace_recursive($config, $dbDefaultConfig); return $config; }