/** * Read configuration by code * * @param string $code * @return array */ public function read($code = null) { if ($this->_appState->isInstalled()) { if (empty($code)) { $store = $this->_storeManager->getStore(); } elseif ($code == \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) { $store = $this->_storeManager->getDefaultStoreView(); } else { $store = $this->_storeFactory->create(); $store->load($code); } if (!$store->getCode()) { throw NoSuchEntityException::singleField('storeCode', $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(array('scope' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scopeId' => $store->getId())); $dbStoreConfig = array(); foreach ($collection as $item) { $dbStoreConfig[$item->getPath()] = $item->getValue(); } $config = $this->_converter->convert($dbStoreConfig, $config); } else { $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource(); $config = $this->_converter->convert($websiteConfig, $this->_initialConfig->getData("stores|{$code}")); } return $config; }
/** * @dataProvider readDataProvider * @param string|null $storeCode * @param string $storeMethod */ public function testRead($storeCode, $storeMethod) { $websiteCode = 'default'; $storeId = 1; $defaultStoreCode = 'foostore'; $defaultStoreId = 2; $websiteMock = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false); $websiteMock->expects($this->any())->method('getCode')->will($this->returnValue($websiteCode)); $this->_storeMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); $this->_storeMock->expects($this->any())->method('load')->with($storeCode); $this->_storeMock->expects($this->any())->method('getId')->will($this->returnValue($storeId)); $this->_storeMock->expects($this->any())->method('getCode')->will($this->returnValue($websiteCode)); $this->_defaultStoreMock->expects($this->any())->method('getWebsite')->will($this->returnValue($websiteMock)); $this->_defaultStoreMock->expects($this->any())->method('load')->with($defaultStoreCode); $this->_defaultStoreMock->expects($this->any())->method('getId')->will($this->returnValue($defaultStoreId)); $this->_defaultStoreMock->expects($this->any())->method('getCode')->will($this->returnValue($defaultStoreCode)); $dataMock = $this->getMock('Magento\\Framework\\App\\Config\\Data', [], [], '', false); $dataMock->expects($this->any())->method('getValue')->will($this->returnValue(['config' => ['key0' => 'website_value0', 'key1' => 'website_value1']])); $dataMock->expects($this->once())->method('getSource')->will($this->returnValue(['config' => ['key0' => 'website_value0', 'key1' => 'website_value1']])); $this->_scopePullMock->expects($this->once())->method('getScope')->with('website', $websiteCode)->will($this->returnValue($dataMock)); $this->_initialConfigMock->expects($this->once())->method('getData')->with("stores|{$storeCode}")->will($this->returnValue(['config' => ['key1' => 'store_value1', 'key2' => 'store_value2']])); $this->_collectionFactory->expects($this->once())->method('create')->with(['scope' => 'stores', 'scopeId' => $storeId])->will($this->returnValue([new Object(['path' => 'config/key1', 'value' => 'store_db_value1']), new Object(['path' => 'config/key3', 'value' => 'store_db_value3'])])); $this->_storeManagerMock->expects($this->any())->method('getDefaultStoreView')->will($this->returnValue($this->_defaultStoreMock)); $this->_storeManagerMock->expects($this->any())->method($storeMethod)->will($this->returnValue($this->_storeMock)); $expectedData = ['config' => ['key0' => 'website_value0', 'key1' => 'store_db_value1', 'key2' => 'store_value2', 'key3' => 'store_db_value3']]; $this->assertEquals($expectedData, $this->_model->read($storeCode)); }
/** * @param mixed $configValue * @param bool $expectedResult * @dataProvider isSetFlagDataProvider */ public function testIsSetFlag($configValue, $expectedResult) { $path = 'some path'; $configData = $this->getConfigDataMock('getValue'); $configData->expects($this->once())->method('getValue')->with($this->equalTo($path))->will($this->returnValue($configValue)); $this->sectionPool->expects($this->once())->method('getScope')->with($this->equalTo('default'), $this->isNull())->will($this->returnValue($configData)); $this->assertEquals($expectedResult, $this->model->isSetFlag($path)); }
/** * 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); }
public function testRead() { $websiteCode = 'default'; $websiteId = 1; $dataMock = $this->getMock('Magento\\Framework\\App\\Config\\Data', [], [], '', false); $dataMock->expects($this->any())->method('getValue')->will($this->returnValue(['config' => ['key0' => 'default_value0', 'key1' => 'default_value1']])); $dataMock->expects($this->once())->method('getSource')->will($this->returnValue(['config' => ['key0' => 'default_value0', 'key1' => 'default_value1']])); $this->_scopePullMock->expects($this->once())->method('getScope')->with('default', null)->will($this->returnValue($dataMock)); $this->_initialConfigMock->expects($this->any())->method('getData')->with("websites|{$websiteCode}")->will($this->returnValue(['config' => ['key1' => 'website_value1', 'key2' => 'website_value2']])); $this->_websiteMock->expects($this->once())->method('load')->with($websiteCode); $this->_websiteMock->expects($this->any())->method('getId')->will($this->returnValue($websiteId)); $this->_collectionFactory->expects($this->once())->method('create')->with(['scope' => 'websites', 'scopeId' => $websiteId])->will($this->returnValue([new \Magento\Framework\Object(['path' => 'config/key1', 'value' => 'website_db_value1']), new \Magento\Framework\Object(['path' => 'config/key3', 'value' => 'website_db_value3'])])); $expectedData = ['config' => ['key0' => 'default_value0', 'key1' => 'website_db_value1', 'key2' => 'website_value2', 'key3' => 'website_db_value3']]; $this->assertEquals($expectedData, $this->_model->read($websiteCode)); }
/** * 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; }
public function testClean() { $this->_cache->expects( $this->once() )->method( 'clean' )->with( \Zend_Cache::CLEANING_MODE_MATCHING_TAG, [\Magento\Framework\App\Config\ScopePool::CACHE_TAG] ); $this->_object->clean('testScope'); }
public function aroundCreate($object, $method, $argument) { if (null === $this->request->getQuery('hint')) { //return early if not hint query return $method($argument); } //force variables debug hints to be enable $paths = ['dev/debug/template_hints_storefront' => 1, 'dev/debug/template_hints_admin' => 1, 'dev/debug/template_hints_blocks' => 1]; $scope = $this->scopePool->getScope(ScopeInterface::SCOPE_STORE, null); foreach ($paths as $path => $value) { $paths[$path] = $scope->getValue($path, $value); //save original value in paths $scope->setValue($path, $value); } //call original method $result = $method($argument); //return original states of variables foreach ($paths as $path => $originalValue) { $scope->setValue($path, $originalValue); } return $result; }
/** * @param \Magento\Framework\DataObject $postObject * * @return bool * @throws \Exception */ public function sendrequest($postObject) { if (!filter_var($postObject->getData('to'), FILTER_VALIDATE_EMAIL)) { throw new \Exception($this->_dataHelper->__('Please enter a valid e-mail address.')); } if (strlen(trim($postObject->getData('replyto')))) { if (!filter_var($postObject->getData('replyto'), FILTER_VALIDATE_EMAIL)) { throw new \Exception($this->_dataHelper->__('Please enter a valid e-mail address (reply to).')); } $this->_transportBuilder->setReplyTo(trim($postObject->getData('replyto'))); } $sender = ['name' => $this->_dataHelper->getStoreConfigData('trans_email/ident_general/name'), 'email' => $this->_dataHelper->getStoreConfigData('trans_email/ident_general/email')]; if (!strlen($sender['email'])) { throw new \Exception('Please set your shop e-mail address!'); } $modules = []; foreach ($this->_moduleLoader->load() as $module) { if (!in_array($module['name'], $this->_moduleBlacklist)) { $modules[] = $module['name']; } } natsort($modules); $payments = $this->_paymentConfig->getActiveMethods(); /** @var \Magento\Framework\App\Config\Data $cfg */ $cfg = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_STORE); $foreign = array(); $mine = array(); foreach ($payments as $paymentCode => $paymentModel) { /** @var AbstractPayment $paymentModel */ $method = array('label' => $paymentModel->getTitle(), 'value' => $paymentCode, 'config' => []); if (preg_match('/^wirecard_/i', $paymentCode)) { $method['config'] = $cfg->getValue('payment/' . $paymentCode); $mine[$paymentCode] = $method; } else { $foreign[$paymentCode] = $method; } } $versioninfo = new \Magento\Framework\DataObject(); $versioninfo->setData($this->_dataHelper->getVersionInfo()); $transport = $this->_transportBuilder->setTemplateIdentifier('contact_support_email')->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->setTemplateVars(['data' => $postObject, 'modules' => $modules, 'foreign' => $foreign, 'mine' => $mine, 'configstr' => $this->_dataHelper->getConfigString(), 'versioninfo' => $versioninfo])->setFrom($sender)->addTo($postObject->getData('to'))->getTransport(); $transport->sendMessage(); return true; }
/** * Retrieve config flag * * @param string $path * @return bool */ public function isSetFlag($path) { return !!$this->_scopePool->getScope(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, null)->getValue($path); }
/** * Retrieve config value by path and scope * * @param string $path * @param string $scope * @param null|string $scopeCode * @return mixed */ public function getValue($path = null, $scope = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, $scopeCode = null) { return $this->_scopePool->getScope($scope, $scopeCode)->getValue($path); }
/** * Retrieve config value by path and scope * * @param string $path * @param string $scope * @param null|string $scopeCode * @return mixed */ public function getValue($path = null, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null) { return $this->_scopePool->getScope($scope, $scopeCode)->getValue($path); }
/** * Retrieve config flag * * @param string $path * @return bool */ public function isSetFlag($path) { return !!$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path); }