Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
config_data.php
Go to the documentation of this file.
1 <?php
12 
13 $objectManager = Bootstrap::getObjectManager();
14 $configFactory = $objectManager->create(Factory::class);
15 $themeList = $objectManager->create(Collection::class);
16 
18  'default' => [
19  'web/test/test_value_1' => 'http://local2.test/',
20  'web/test/test_value_2' => 5,
21  'web/test/test_value_3' => 'value from the DB',
22  'web/test/test_sensitive' => 10,
23  'general/country/default' => 'GB',
24 
25  'web/test/test_sensitive1' => 'some_value1',
26  'web/test/test_sensitive2' => 'some_value2',
27  'web/test/test_sensitive3' => 'some_value3',
28  'web/test/test_sensitive_environment4' => 'some_value4',
29  'web/test/test_sensitive_environment5' => 'some_value5',
30  'web/test/test_sensitive_environment6' => 'some_value6',
31  'web/test/test_environment7' => 'some_value7',
32  'web/test/test_environment8' => 'some_value8',
33  'web/test/test_environment9' => 'some_value9',
34  DesignInterface::XML_PATH_THEME_ID => $themeList->getThemeByFullPath('frontend/Magento/blank')->getThemeId()
35  ],
36  'stores' => [
37  'default' => [
38  DesignInterface::XML_PATH_THEME_ID => $themeList->getThemeByFullPath('frontend/Magento/luma')->getThemeId()
39  ]
40  ],
41  'websites' => [
42  'base' => [
43  DesignInterface::XML_PATH_THEME_ID => $themeList->getThemeByFullPath('frontend/Magento/luma')->getThemeId()
44  ]
45  ],
46 ];
47 
48 foreach ($configData as $scope => $data) {
49  if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
50  foreach ($data as $path => $value) {
51  $config = $configFactory->create();
52  $config->setScope($scope);
53  $config->setDataByPath($path, $value);
54  $config->save();
55  }
56  } else {
57  foreach ($data as $scopeCode => $scopeData) {
58  foreach ($scopeData as $path => $value) {
59  $config = $configFactory->create();
60  if ($scope == 'websites') {
61  $config->setWebsite($scopeCode);
62  } elseif ($scope == 'stores') {
63  $config->setStore($scopeCode);
64  } else {
65  $config->setScope($scope);
66  }
67  $config->setDataByPath($path, $value);
68  $config->save();
69  }
70  }
71  }
72 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$configData
Definition: config_data.php:12
$value
Definition: gender.phtml:16
$objectManager
Definition: config_data.php:41
$themeList
Definition: config_data.php:15
$configFactory
Definition: config_data.php:43
$config
Definition: config_data.php:15