I have two store available in Magento
- Default store View
- German Store
In Default Store View I have one tab Blog => General => Store Information. I stored value from this field and it will be store in General => General => Store Information.
But in German Store View which value i fill in Blog=> General => Store Information that will be not stored in General => General => Store Information.
How it is possible that I can store value in General => General => Store Information which I fill in Blog => General => Store Information in German Store View?
Please help me...
Model/Observer/Storeinfo.php
$store = $this->_request->getParam('store'); if($store == '1') { $showTemplateHint = $this->_scopeConfig->getValue('general_tab/general/display_text', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); echo "Default :- ".$showTemplateHint; exit; $this->resourceConfig->saveConfig('general/store_information/name', $showTemplateHint, 'default', 0); } if($store == '2') { $showTemplate = $this->_scopeConfig->getValue('general_tab/general/display_text', 2); echo "German :- ".$showTemplate; exit; $this->resourceConfig->saveConfig('general/store_information/name', $showTemplate, 'stores', 2); }
2 Answers 2
As far as I understand your question you want to get config value for different store. Hope this help you
//get our current store
$store = $this->_storeManager->getStore();
//get value for store
$configValue = $this->_scopeConfig->getValue(
'needed/value',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
//but you can put here another store(not current)
$store
);
In system.xml you can write like this
//copied from www.mageplaza.com -- No Offence :P and below code is not tested.//
<?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="mageplaza" translate="label" sortOrder="10">
<label>Mageplaza</label>
</tab>
<section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Hello World</label>
<tab>mageplaza</tab>
<resource>Mageplaza_HelloWorld::hello_configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</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>Display Text</label>
<comment>This text will display on the frontend.</comment>
</field>
</group>
</section>
</system>
</config>
showInDefault="1" showInWebsite="0" showInStore="0" check this part in above code. This basically makes your field global or website specific or store specific.
Or if you want to access data then follow this Magento 2 - How to get value in "core_config_data" table which is basically like this
$this->scopeConfig->getValue('section id/group id/field id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
-
See my observer file code sir... I already apply this code but still it's not working.... If i apply this => showInDefault="1" showInWebsite="0" showInStore="0" ...then that field not display in other store.Rohan Hapani– Rohan Hapani2017年04月05日 09:24:20 +00:00Commented Apr 5, 2017 at 9:24
-
You dont need an observer to do this. You can do this from system.xml instead. If you want same value for both then why do you want it in other stores ? Just declare the scope to global like i said. And in which event your observer gets fired ?Kingshuk Deb– Kingshuk Deb2017年04月05日 09:34:50 +00:00Commented Apr 5, 2017 at 9:34
-
1No . I don't want to get same value. For ex :- Default Store => Blog => Genereal => Store information = "ABC" .. Then in Default => General => General => Store information ="ABC" will be display. But German Store => Blog => General => Store informartion = "DEF"..Then Then in German => General => General => Store information ="DEF" will be displayed. But DEF is not displayed. I want to display DEF in German => General => General => Store information ="DEF"Rohan Hapani– Rohan Hapani2017年04月05日 11:39:34 +00:00Commented Apr 5, 2017 at 11:39
-
That means its website specific. Then try this showInDefault="0" showInWebsite="1" showInStore="0". In that case all stores in that website will have the same value.Kingshuk Deb– Kingshuk Deb2017年04月05日 11:46:52 +00:00Commented Apr 5, 2017 at 11:46
-
1It's sovled => First of all, get value from params ...$param = $this->_request->getParams(); Then print it... & find where your value is store & store in variable. For Ex. :- $showTemplate = $param['groups']['store_information']['fields']['name']['value'];Rohan Hapani– Rohan Hapani2017年04月05日 12:27:40 +00:00Commented Apr 5, 2017 at 12:27
Explore related questions
See similar questions with these tags.
$this->scopeConfig->getValue('section id/group id/field id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);or try this magento.stackexchange.com/questions/112821/…