2

I have two store available in Magento

  1. Default store View
  2. 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);
    }
    

enter image description here

3
  • Do not make it store specific. if you want same value for all stores then make it website specific or kind of Global. Apr 5, 2017 at 7:36
  • Or if you just want to get the data from store config then use like this $this->scopeConfig->getValue('section id/group id/field id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); or try this magento.stackexchange.com/questions/112821/… Apr 5, 2017 at 7:44
  • 1
    @KingshukDeb I already use that code but still it's not working ... In German Store I get value of default store view. Apr 5, 2017 at 9:21

2 Answers 2

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
);
1

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);
6
  • 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. 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 ? Apr 5, 2017 at 9:34
  • 1
    No . 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" 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. Apr 5, 2017 at 11:46
  • 1
    It'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']; Apr 5, 2017 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.