Ejemplo n.º 1
1
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider getScopeDataProvider
  *
  * @param string $scopeType
  * @param string $scope
  * @param array $data
  * @param string|null $cachedData
  */
 public function testGetScope($scopeType, $scope, array $data, $cachedData)
 {
     $scopeCode = $scope instanceof \Magento\Framework\App\ScopeInterface ? $scope->getCode() : $scope;
     $cacheKey = "test_cache_id|{$scopeType}|{$scopeCode}";
     $this->_readerPool->expects($this->any())->method('getReader')->with($scopeType)->will($this->returnValue($this->_reader));
     $this->_cache->expects($this->once())->method('load')->with($cacheKey)->will($this->returnValue($cachedData));
     if (!$cachedData) {
         $this->_reader->expects($this->once())->method('read')->with('testScope')->will($this->returnValue($data));
         $this->_cache->expects($this->once())->method('save')->with(serialize($data), $cacheKey, array(\Magento\Framework\App\Config\ScopePool::CACHE_TAG));
     }
     $configData = $this->getMockBuilder('\\Magento\\Framework\\App\\Config\\Data')->disableOriginalConstructor()->getMock();
     $this->_dataFactory->expects($this->once())->method('create')->with(array('data' => $data))->will($this->returnValue($configData));
     $this->assertInstanceOf('\\Magento\\Framework\\App\\Config\\DataInterface', $this->_object->getScope($scopeType, $scope));
     // second call to check caching
     $this->assertInstanceOf('\\Magento\\Framework\\App\\Config\\DataInterface', $this->_object->getScope($scopeType, $scope));
 }
 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;
 }
Ejemplo n.º 6
0
 /**
  * @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;
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * 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);
 }
Ejemplo n.º 10
0
 /**
  * Retrieve config flag
  *
  * @param string $path
  * @return bool
  */
 public function isSetFlag($path)
 {
     return !!$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path);
 }