How to get value from core_config_data table and set as default value in config.xml file in magento2
I want to add value from
BLOG > General > Store Information > Store name and set value in General > General > Store Information > Store name
which i added.
How it is possible? Please help me...
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="abc" translate="label" sortOrder="10">
<label>abc</label>
</tab>
<section id="general_tab" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>General</label>
<tab>abc</tab>
<resource>abc_Blog::config_blog</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Store Information</label>
<!-- <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field> -->
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Store name</label>
<!-- <comment>This text will display on the frontend.</comment> -->
</field>
<field id="display_text2" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Store name2</label>
<!-- <comment>This text will display on the frontend.</comment> -->
</field>
</group>
</section>
</system>
</config>
Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Apr 4, 2017 at 7:33
Rohan Hapani
17.6k9 gold badges57 silver badges99 bronze badges
-
Please share system.xml file of this modulesAmit Bera– Amit Bera ♦2017年04月04日 07:53:16 +00:00Commented Apr 4, 2017 at 7:53
-
see this code... please help me.Rohan Hapani– Rohan Hapani2017年04月04日 09:18:16 +00:00Commented Apr 4, 2017 at 9:18
1 Answer 1
You need include the Magento\Store\Model\ScopeInterface class consturctor
protected $_scopeConfig;
public function __construct(
...
\Magento\Store\Model\ScopeInterface $scopeInterface,
...
)
{
...
$this->_scopeConfig = $scopeInterface;
...
}
In Your specific place call:
$this->scopeConfig->getValue('general_tab/general/display_text', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
-
1$this->scopeConfig->getValue('general_tab/general/display_text', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); .............. this value i want to stored in "general/store_information/name" using saveConfig() .... how it is possible?Rohan Hapani– Rohan Hapani2017年04月04日 11:06:03 +00:00Commented Apr 4, 2017 at 11:06
-
its solved : => put this below code in observer => execute() function $showTemplateHint = $this->_scopeConfig->getValue('general_tab/general/display_text', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); .................................. $this->resourceConfig->saveConfig('general/store_information/name', $showTemplateHint, 'default', 0);Rohan Hapani– Rohan Hapani2017年04月04日 12:00:54 +00:00Commented Apr 4, 2017 at 12:00
-
1How can i set use this tab in other store view & store value in 'core_config_data' table ?Rohan Hapani– Rohan Hapani2017年04月05日 04:37:06 +00:00Commented Apr 5, 2017 at 4:37
Explore related questions
See similar questions with these tags.
default