diff --git a/Block/Adminhtml/Linv.php b/Block/Adminhtml/Linv.php index 43cb41c..f99c1d0 100644 --- a/Block/Adminhtml/Linv.php +++ b/Block/Adminhtml/Linv.php @@ -46,13 +46,38 @@ public function __construct( */ public function getItems() { + $path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v'; + $condition = '='; + $value = 1; + + return $this->fetchConfigData($path, $condition, $value); + } + + /** + * @return array + */ + public function getMessages() { + $path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v'.'me'.'ss'.'ag'.'e'; + $condition = '!='; + $value = ''; + + return $this->fetchConfigData($path, $condition, $value); + } + + /** + * @param string $path + * @param string $condition + * @param $value + * @return array + */ + private function fetchConfigData(string $path, string $condition, $value) { $connection = $this->resource->getConnection(); $table = $this->resource->getTableName('core_config_data'); - $path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v'; + $select = $connection->select() ->from([$table]) ->where( 'path LIKE ?', '%' . $path ) - ->where('value = ?',1); + ->where('value ' . $condition . ' ?', $value); $items = $connection->fetchAll($select); $result = []; @@ -66,7 +91,6 @@ public function getItems() if ($module && !$section->isEnabled()) { $result[] = $module; } - } return $result; } diff --git a/Model/Section.php b/Model/Section.php index 79064aa..5becb0e 100644 --- a/Model/Section.php +++ b/Model/Section.php @@ -190,6 +190,19 @@ final public function validate($data) return false; } + /** + * @param $data + * @return false|string + */ + final public function getErrorMessage($data) + { + if (isset($data[$this->getModule(). '_errorMsg'])) { + return (string)$data[$this->getModule(). '_errorMsg']; + } + + return false; + } + /** * @param string $id * @param string $k diff --git a/Model/Section/Info.php b/Model/Section/Info.php index f790c0d..740ac7e 100644 --- a/Model/Section/Info.php +++ b/Model/Section/Info.php @@ -9,6 +9,7 @@ use Magento\Framework\App\ProductMetadataInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\HTTP\Client\Curl; +use Magefan\Community\Model\GetModuleVersion; /** * Class Section Info @@ -31,21 +32,28 @@ final class Info */ private $curl; + /** + * @var GetModuleVersion + */ + private $modelModuleVersion; + /** * Info constructor. * @param ProductMetadataInterface $metadata * @param StoreManagerInterface $storeManager * @param Curl $curl - * @param array $data + * @param GetModuleVersion $modelModuleVersion */ final public function __construct( ProductMetadataInterface $metadata, StoreManagerInterface $storeManager, - Curl $curl + Curl $curl, + GetModuleVersion $modelModuleVersion ) { $this->metadata = $metadata; $this->storeManager = $storeManager; $this->curl = $curl; + $this->modelModuleVersion = $modelModuleVersion; } /** @@ -84,9 +92,11 @@ private function getSectionsParam(array $sections) { $result = []; foreach ($sections as $section) { - $result[$section->getModule()] = [ + $module = $section->getModule(); + $result[$module] = [ 'key' => $section->getKey(), - 'section' => $section->getName() + 'section' => $section->getName(), + 'version' => $this->modelModuleVersion->execute('Magefan_' . $module) ]; } return $result; diff --git a/Model/SetLinvFlag.php b/Model/SetLinvFlag.php index 3a148f9..1cd6b61 100644 --- a/Model/SetLinvFlag.php +++ b/Model/SetLinvFlag.php @@ -47,4 +47,15 @@ public function execute($module, $value) $this->configWriter->save($module . '/g'.'en'.'er'.'al'.'/l'.'in'.'v', $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); $this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER); } + + /** + * @param $module + * @param $message + * @return void + */ + public function addMessage($module, $message) + { + $this->configWriter->save($module . '/g'.'en'.'er'.'al'.'/l'.'in'.'v'.'me'.'ss'.'ag'.'e', $message, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0); + $this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER); + } } diff --git a/Observer/ConfigObserver.php b/Observer/ConfigObserver.php index 6aaf61b..9995c36 100644 --- a/Observer/ConfigObserver.php +++ b/Observer/ConfigObserver.php @@ -106,14 +106,18 @@ final public function execute(\Magento\Framework\Event\Observer $observer) } $module = $section->getName(); $data = $this->info->load([$section]); + $errorMessage = $section->getErrorMessage($data); if (!$section->validate($data)) { $groups['general']['fields']['enabled']['value'] = 0; $this->setLinvFlag->execute($module, 1); $request->setPostValue('groups', $groups); - $this->messageManager->addError( - implode(array_reverse( + if ($errorMessage) { + $this->setLinvFlag->addMessage($module, $errorMessage); + $this->messageManager->addError($errorMessage); + } else { + $message = implode(array_reverse( [ '.','d','e','l','b','a','s','i','d',' ','y','l','l','a','c','i','t','a','m', 'o','t','u','a',' ','n','e','e','b',' ','s','a','h',' ','n','o','i','s','n', @@ -121,9 +125,12 @@ final public function execute(\Magento\Framework\Event\Observer $observer) 'o',' ','y','t','p','m','e',' ','s','i',' ','y','e','K',' ','t','c','u','d', 'o','r','P' ] - )) - ); + )); + $this->setLinvFlag->addMessage($module, $message); + $this->messageManager->addError($message); + } } else { + $this->setLinvFlag->addMessage($module, ''); $this->setLinvFlag->execute($module, 0); } } diff --git a/view/adminhtml/templates/linv.phtml b/view/adminhtml/templates/linv.phtml index ea345ca..6ed95cb 100644 --- a/view/adminhtml/templates/linv.phtml +++ b/view/adminhtml/templates/linv.phtml @@ -10,11 +10,13 @@ * * @var $block \Magefan\Community\Block\Adminhtml\Linv */ +$items = $block->getItems(); +$messages = $block->getMessages(); ?> getItems()) { ?>