1

Is there any class/file from module-config module that can be useful whether single_store_mode value has been changed from yes to no or vice-versa.

Have checked admin_config related events but these are not useful as these are calling after save.

EDIT:

I want to have before Save as well as after Save value so i can compare whether value has been changed or not?

Tried to implement two approaches but unfortunately it's not working.

  1. By applying source_model on the general/single_store_mode/enabled in custom module's system.xml

  2. Using beforeSave() plugin on Magento\Config\Model\Config

2

Inject \Magento\Framework\App\Config\ScopeConfigInterface and use $this->scopeConfig->getValue('general/single_store_mode/enabled'); to read the value.

| improve this answer | |
  • Thanks for the answer. – MageSoftech Dec 3 '19 at 14:01
-1

Or you can use then @Philipp Sander solution in a more elegant way

app/code/Vendor/Module/Helper/Data.php

namespace Vendor\Module\Helper;

use Magento\Framework\App\Config\ScopeConfigInterface;


class Data extends \Magento\Framework\App\Helper\AbstractHelper

{

    protected $_scopeConfig;

    public function __construct(
        ScopeConfigInterface $scopeConfig
    ) {
        $this->_scopeConfig = $scopeConfig;
    }


    /**
    * Use scope magento config
    *
    * @param string $config_path
    */

    public function getStoreConfig($config_path)
    {
        return $this->_scopeConfig->getValue(
            $config_path,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }
}

Then you inject that helper in your constructor

protected $_helper;

public function __construct(
    ...
    \Vendor\Module\Helper\Data $helper 
) {
    ...
    $this->_helper = $helper;
}

 public function execute() {
    $singleStoreMode = $this->_helper->getStoreConfig('general/single_store_mode/enabled');
}

Note : Don't forget to generate the new DI classes :

php bin/magento setup:di:compile
| improve this answer | |
  • this is exactly what I said. How is it more elegant to wrap it in a helper? – Philipp Sander Dec 3 '19 at 12:46
  • @Philipp Sander it's more elegant to use getStoreConfig() function and use it in other files if needed, it also good what you did, that's why I gave you +1 – PЯINCƏ Dec 3 '19 at 13:55
  • when extending a class, you should make sure that the parent constructor is being called. and if you take a look at abstracthelper you will see that it already has a scopeconfig. so no need to inject it again. what excatly is you benefit of having that helper? why not inject scopeconfig into your service directly? – Philipp Sander Dec 3 '19 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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