diff --git a/Block/Adminhtml/System/Config/BundleProduct.php b/Block/Adminhtml/System/Config/BundleProduct.php new file mode 100644 index 0000000..7aa7b94 --- /dev/null +++ b/Block/Adminhtml/System/Config/BundleProduct.php @@ -0,0 +1,33 @@ +moduleManager = $moduleManager; + parent::__construct($context, $data, $jsonHelper, $directoryHelper); + } + + public function getModules() + { + return $this->moduleManager->getAllSections(); + } +} \ No newline at end of file diff --git a/Model/ModuleManager.php b/Model/ModuleManager.php new file mode 100644 index 0000000..7c89962 --- /dev/null +++ b/Model/ModuleManager.php @@ -0,0 +1,89 @@ + [ + 'plus' => ['mfrichsnippets','mfxmlsitemap','mfhs'], + 'extra' => ['alternatehreflang','mfogt','mftwittercards'] + ], + 'mfspeedoptimizations' => [ + 'base' => ['mflazyzoad','mfrocketjavascript'], + 'plus' => ['mfwebp'], + 'extra' => ['mfpagecachewarmer'] + ], + ]; + + /** + * @var GetModuleVersion + */ + private $getModuleVersion; + + /** + * @var SectionFactory + */ + private $sectionFactory; + + /** + * @param GetModuleVersion $getModuleVersion + * @param SectionFactory $sectionFactory + */ + public function __construct( + GetModuleVersion $getModuleVersion, + SectionFactory $sectionFactory + ) + { + $this->getModuleVersion = $getModuleVersion; + $this->sectionFactory = $sectionFactory; + } + + /** + * @return array + */ + public function getAllSections() + { + $allInstModule = []; + foreach ($this->moduleManager as $section => $plans) { + $extensionName = $this->sectionFactory->create(['name' => $section])->getModuleName(); + $extensionName = str_replace(['Extra','Plus'],'', $extensionName); + foreach ($plans as $key => $modules) { + if ($key == 'base' ||$this->getModuleVersion->execute('Magefan_' . $extensionName . ucfirst($key))) { + $allInstModule[$section] = array_merge($allInstModule[$section] ?? [], $modules); + } + } + } + + return $allInstModule; + } + + /** + * @param $name + * @return array|null + */ + public function getSectionByName($name) + { + if (isset($this->moduleManager[$name])) { + $sections = []; + foreach ($this->moduleManager[$name] as $plan => $data) { + foreach ($data as $section) { + $extensionName = $this->sectionFactory->create(['name' => $section])->getModuleName(); + $extensionName = str_replace(['Extra','Plus'],'', $extensionName); + if ($plan == 'base' || $this->getModuleVersion->execute('Magefan_' . $extensionName . ucfirst($plan))) { + $sections[] = $section; + } + } + + } + return $sections; + } + return null; + } +} \ No newline at end of file diff --git a/Model/SystemConfigAutoKeyManager.php b/Model/SystemConfigAutoKeyManager.php new file mode 100644 index 0000000..57aa8fd --- /dev/null +++ b/Model/SystemConfigAutoKeyManager.php @@ -0,0 +1,86 @@ +configWriter = $configWriter; + $this->getModuleVersion = $getModuleVersion; + $this->moduleManager = $moduleManager; + $this->scopeConfig = $scopeConfig; + $this->sectionFactory = $sectionFactory; + } + + /** + * @param string $section + * @param string $key + * @return void + */ + public function execute(string $section, string $key) { + $sections = $this->moduleManager->getSectionByName($section); + + if ($sections) { + foreach ($sections as $section) { + $sectionData = $this->sectionFactory->create(['name' => $section]); + $alreadyExist = $this->scopeConfig->getValue( + $sectionData->getName() . '/g'.'en'.'er'.'al'.'/k'.'e'.'y', + ScopeInterface::SCOPE_STORE + ); + + if ($sectionData->getModule() && !$alreadyExist) { + $this->configWriter->save($section . '/g'.'en'.'er'.'al'.'/k'.'e'.'y', $key); + } + } + } + } +} \ No newline at end of file diff --git a/Observer/ConfigObserver.php b/Observer/ConfigObserver.php index 6aaf61b..18fa088 100644 --- a/Observer/ConfigObserver.php +++ b/Observer/ConfigObserver.php @@ -6,6 +6,7 @@ namespace Magefan\Community\Observer; +use Magefan\Community\Model\SystemConfigAutoKeyManager; use Magento\Framework\Event\ObserverInterface; use Magefan\Community\Model\SectionFactory; use Magefan\Community\Model\Section\Info; @@ -44,6 +45,11 @@ class ConfigObserver implements ObserverInterface */ private $config; + /** + * @var SystemConfigAutoKeyManager + */ + private $autoKeyManager; + /** * ConfigObserver constructor. * @param SectionFactory $sectionFactory @@ -51,19 +57,22 @@ class ConfigObserver implements ObserverInterface * @param ManagerInterface $messageManager * @param SetLinvFlag $setLinvFlag * @param Config $config + * @param SystemConfigAutoKeyManager $autoKeyManager */ final public function __construct( SectionFactory $sectionFactory, Info $info, ManagerInterface $messageManager, SetLinvFlag $setLinvFlag, - Config $config + Config $config, + SystemConfigAutoKeyManager $autoKeyManager ) { $this->sectionFactory = $sectionFactory; $this->info = $info; $this->messageManager = $messageManager; $this->setLinvFlag = $setLinvFlag; $this->config = $config; + $this->autoKeyManager = $autoKeyManager; } /** @@ -125,6 +134,9 @@ final public function execute(\Magento\Framework\Event\Observer $observer) ); } else { $this->setLinvFlag->execute($module, 0); + if ($key) { + $this->autoKeyManager->execute($section->getName(),$key); + } } } } diff --git a/view/adminhtml/layout/adminhtml_system_config_edit.xml b/view/adminhtml/layout/adminhtml_system_config_edit.xml new file mode 100644 index 0000000..712c6c1 --- /dev/null +++ b/view/adminhtml/layout/adminhtml_system_config_edit.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/view/adminhtml/templates/mfconfig-section.phtml b/view/adminhtml/templates/mfconfig-section.phtml new file mode 100644 index 0000000..7f2a8e0 --- /dev/null +++ b/view/adminhtml/templates/mfconfig-section.phtml @@ -0,0 +1,125 @@ + + + + +