config = $config; $this->reinitableConfig = $reinitableConfig; $this->configWriter = $configWriter; } /** * @param Observer $observer */ public function execute(Observer $observer) { $name = $observer->getEvent()->getName(); $catalogValue = $this->getCatalogValue(); $moduleValue = $this->getElasticModuleValue(); if ($catalogValue != $moduleValue) { switch ($name) { case 'admin_system_config_changed_section_catalog': $this->saveElasticValue($catalogValue); break; case 'admin_system_config_changed_section_amasty_elastic': $this->saveCatalogValue($moduleValue); break; } } } /** * @param $value */ private function saveElasticValue($value) { $this->saveConfig(Config::CONFIG_ENGINE_PATH, $value); } /** * @param $value */ private function saveCatalogValue($value) { $this->saveConfig(EngineInterface::CONFIG_ENGINE_PATH, $value); } /** * @param string $path * @param string $value * @return $this */ private function saveConfig($path, $value) { $this->configWriter->save($path, $value); $this->reinitableConfig->reinit(); return $this; } /** * @return string */ private function getCatalogValue() { return $this->config->getGeneralConfig(EngineInterface::CONFIG_ENGINE_PATH); } /** * @return string */ private function getElasticModuleValue() { return $this->config->getEngine(); } }