Пример #1
0
 public function testSaveDeleteConfig()
 {
     $connection = $this->_model->getReadConnection();
     $select = $connection->select()->from($this->_model->getMainTable())->where('path=?', 'test/config');
     $this->_model->saveConfig('test/config', 'test', 'default', 0);
     $this->assertNotEmpty($connection->fetchRow($select));
     $this->_model->deleteConfig('test/config', 'default', 0);
     $this->assertEmpty($connection->fetchRow($select));
 }
Пример #2
0
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function updateOrderStatusForPaymentMethods(\Magento\Framework\Event\Observer $observer)
 {
     if ($observer->getEvent()->getState() != \Magento\Sales\Model\Order::STATE_NEW) {
         return;
     }
     $status = $observer->getEvent()->getStatus();
     $defaultStatus = $this->_salesOrderConfig->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_NEW);
     $methods = $this->_paymentConfig->getActiveMethods();
     foreach ($methods as $method) {
         if ($method->getConfigData('order_status') == $status) {
             $this->_resourceConfig->saveConfig('payment/' . $method->getCode() . '/order_status', $defaultStatus, 'default', 0);
         }
     }
 }
Пример #3
0
 public function testScheduledUpdateCurrencyRates()
 {
     //skipping test if service is unavailable
     $url = str_replace('{{CURRENCY_FROM}}', 'USD', \Magento\Directory\Model\Currency\Import\Webservicex::CURRENCY_CONVERTER_URL);
     $url = str_replace('{{CURRENCY_TO}}', 'GBP', $url);
     try {
         file_get_contents($url);
     } catch (\PHPUnit_Framework_Error_Warning $e) {
         $this->markTestSkipped('http://www.webservicex.net is unavailable ');
     }
     $allowedCurrencies = 'USD,GBP,EUR';
     $this->configResource->saveConfig($this->allowedCurrenciesPath, $allowedCurrencies, ScopeInterface::SCOPE_STORE, 0);
     $this->observer->scheduledUpdateCurrencyRates(null);
     /** @var Currency $currencyResource */
     $currencyResource = $this->objectManager->create('Magento\\Directory\\Model\\CurrencyFactory')->create()->getResource();
     $rates = $currencyResource->getCurrencyRates($this->baseCurrency, explode(',', $allowedCurrencies));
     $this->assertNotEmpty($rates);
 }
 /**
  * Save the configuration value in both core and module db tables.
  *
  * @param $path
  * @param $scopeId
  * @param $value
  * @param string $type
  */
 protected function _saveConfig($path, $scopeId, $value, $type = self::TYPE_NORMAL)
 {
     // do not save config if path validation fails.
     if (!($fullPathParts = $this->_validateFullPath($path))) {
         return;
     }
     if ($type === self::TYPE_ENCRYPTED) {
         $value = $this->_encryptor->encrypt($value);
     }
     // get the path from the parts of path
     $path = implode('/', array_slice($fullPathParts, 1, 3));
     $this->_coreConfigResource->saveConfig($path, $value, $fullPathParts[0], $scopeId);
     $this->_configModel->setData(['scope_type' => $fullPathParts[0], 'scope_id' => $scopeId, 'path' => $path, 'value' => $value]);
     $this->_configModel->save();
     $this->_configModel->clearInstance();
 }
Пример #5
0
 /**
  * Reset flag for showing tax notifications
  *
  * @param string $path
  * @return \Magento\Tax\Model\Config\Notification
  */
 protected function _resetNotificationFlag($path)
 {
     $this->resourceConfig->saveConfig($path, 0, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
     return $this;
 }
Пример #6
0
 /**
  * Reset flag for showing tax notifications
  *
  * @param string $path
  * @return \Magento\Tax\Model\Config\Notification
  */
 protected function _resetNotificationFlag($path)
 {
     $this->resourceConfig->saveConfig($path, 0, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT, 0);
     return $this;
 }
 public function execute()
 {
     $error = false;
     $output = '';
     $config = $this->getRequest()->getParam('config');
     try {
         if (empty($config['key'])) {
             throw new \Exception('Key is missing');
         } else {
             $configKey = $config['key'];
         }
         $scopeList = array('default', 'websites', 'stores', 'auto');
         if (empty($config['scope']) or !in_array($config['scope'], $scopeList)) {
             throw new \Exception('Scope is missing');
         } else {
             $configScope = $config['scope'];
             if ($configScope == 'auto') {
                 switch ($configKey) {
                     case 'hints':
                     case 'translate':
                         $configScope = 'stores';
                         break;
                     default:
                         throw new \Exception('Scope auto is unrecognized');
                         break;
                 }
             }
         }
         if (empty($config['value'])) {
             $configValue = 1;
         } else {
             $configValue = $config['value'];
         }
         switch ($configScope) {
             case 'stores':
                 $configScopeId = $this->_storeManager->getStore()->getId();
                 break;
             case 'websites':
                 $configScopeId = $this->_storeManager->getWebsite()->getId();
                 break;
             default:
                 $configScopeId = 0;
                 break;
         }
         switch ($configKey) {
             case 'hints':
                 $configValue = $this->_qdbHelper->getConfig('dev/debug/template_hints', $configScope, $configScopeId) ? 0 : 1;
                 $this->_resourceConfig->saveConfig('dev/debug/template_hints', $configValue, $configScope, $configScopeId);
                 $this->_resourceConfig->saveConfig('dev/debug/template_hints_blocks', $configValue, $configScope, $configScopeId);
                 $output = "Hints set " . ($configValue ? 'On' : 'Off');
                 break;
             case 'translate':
                 $configValue = $this->_qdbHelper->getConfig('dev/translate_inline/active', $configScope, $configScopeId) ? 0 : 1;
                 $this->_resourceConfig->saveConfig('dev/translate_inline/active', $configValue, $configScope, $configScopeId);
                 $output = "Translate set " . ($configValue ? 'On' : 'Off');
                 break;
             default:
                 break;
         }
         if ($output) {
             $this->_qdbHelper->setControllerMessage($output);
         }
     } catch (\Exception $e) {
         $output = $e->getMessage();
         $error = true;
     }
     if (!$error) {
         /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
         $resultForward = $this->_resultForwardFactory->create();
         $resultForward->forward('cache');
         return $resultForward;
     } else {
         $this->_view->loadLayout();
         $resultRaw = $this->_resultRawFactory->create();
         return $resultRaw->setContents($output);
     }
 }