Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
  3. <system>
  4. <tab id="mymodule" translate="label" sortOrder="100">
  5. <label>My Module</label>
  6. </tab>
  7. <section id="mymodule" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
  8. <label>My Module</label>
  9. <tab>myconfig</tab>
  10. <resource>Vendor_Module::system_config</resource>
  11. <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
  12. <label>General Configuration</label>
  13. <field id="enable" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
  14. <label>Enable Module</label>
  15. <source_model>MagentoConfigModelConfigSourceEnabledisable</source_model>
  16. </field>
  17. </group>
  18. </section>
  19. </system>
  20. </config>
  21.  
  22. class Myclass
  23. {
  24. public function __construct(
  25. MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
  26. ){
  27. $this->scopeConfig = $scopeConfig;
  28. }
  29.  
  30. public function isModuleEnabled($website = null)
  31. {
  32. return $this->scopeConfig->isSetFlag(
  33. 'mymodule/general/enable',
  34. MagentoStoreModelScopeInterface::SCOPE_WEBSITE,
  35. $website
  36. );
  37. }
  38.  
  39. public function execute()
  40. {
  41. if ($this->isModuleEnabled()) {
  42. // Do stuff here if module is enabled.
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement