Skip to content

Commit 33bc5e2

Browse files
committed
Ticket 12893
1 parent a88934f commit 33bc5e2

File tree

6 files changed

+86
-24
lines changed

6 files changed

+86
-24
lines changed

Block/Adminhtml/Linv.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
/**
4545
* @return array
4646
*/
47-
public function getItems()
47+
public function getItems(): array
4848
{
4949
$connection = $this->resource->getConnection();
5050
$table = $this->resource->getTableName('core_config_data');
@@ -70,4 +70,35 @@ public function getItems()
7070
}
7171
return $result;
7272
}
73+
74+
/**
75+
* @return array
76+
*/
77+
public function getMessages():array
78+
{
79+
$connection = $this->resource->getConnection();
80+
$table = $this->resource->getTableName('core_config_data');
81+
$path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v'.'_'.'error_me'.'ss'.'ag'.'e';
82+
$select = $connection->select()
83+
->from([$table])
84+
->where( 'path LIKE ?', '%' . $path )
85+
->where('value != ?','');
86+
$items = $connection->fetchAll($select);
87+
$result = [];
88+
89+
foreach ($items as $config) {
90+
$configPath = explode('/', $config['path']);
91+
$moduleName = $configPath[0];
92+
$section = $this->sectionFactory->create([
93+
'name' => $moduleName
94+
]);
95+
$module = $section->getModule(true);
96+
if ($module) {
97+
$result[$module] = $config['value'];
98+
}
99+
100+
}
101+
102+
return $result;
103+
}
73104
}

Cron/Sections.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ public function execute()
9494

9595
if ($data && is_array($data)) {
9696
foreach ($data as $module => $item) {
97+
if (!isset($sections[$module])) {
98+
continue;
99+
}
97100
$section = $sections[$module];
98-
$moduleName = $section->getName();
101+
$errorMessage = $data[$module . '_errorMsg'] ?? '';
102+
99103
if (!$section->validate($data)) {
100104
$connection->update(
101105
$table,
@@ -104,9 +108,10 @@ public function execute()
104108
],
105109
['path = ? ' => $section->getName() . '/' . $path]
106110
);
107-
$this->setLinvFlag->execute($moduleName, 1);
111+
112+
$this->setLinvFlag->execute($section->getName(), 1, $errorMessage);
108113
} else {
109-
$this->setLinvFlag->execute($moduleName, 0);
114+
$this->setLinvFlag->execute($section->getName(), 0, $errorMessage);
110115
}
111116
}
112117
}

Model/Section/Info.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\ProductMetadataInterface;
1010
use Magento\Store\Model\StoreManagerInterface;
1111
use Magento\Framework\HTTP\Client\Curl;
12+
use Magefan\Community\Model\GetModuleVersion;
1213

1314
/**
1415
* Class Section Info
@@ -31,21 +32,28 @@ final class Info
3132
*/
3233
private $curl;
3334

35+
/**
36+
* @var GetModuleVersion
37+
*/
38+
private $modelModuleVersion;
39+
3440
/**
3541
* Info constructor.
3642
* @param ProductMetadataInterface $metadata
3743
* @param StoreManagerInterface $storeManager
3844
* @param Curl $curl
39-
* @param array $data
45+
* @param GetModuleVersion $modelModuleVersion
4046
*/
4147
final public function __construct(
4248
ProductMetadataInterface $metadata,
4349
StoreManagerInterface $storeManager,
44-
Curl $curl
50+
Curl $curl,
51+
GetModuleVersion $modelModuleVersion
4552
) {
4653
$this->metadata = $metadata;
4754
$this->storeManager = $storeManager;
4855
$this->curl = $curl;
56+
$this->modelModuleVersion = $modelModuleVersion;
4957
}
5058

5159
/**
@@ -84,9 +92,11 @@ private function getSectionsParam(array $sections)
8492
{
8593
$result = [];
8694
foreach ($sections as $section) {
87-
$result[$section->getModule()] = [
95+
$module = $section->getModule();
96+
$result[$module] = [
8897
'key' => $section->getKey(),
89-
'section' => $section->getName()
98+
'section' => $section->getName(),
99+
'version' => $this->modelModuleVersion->execute('Mag' . 'e' . 'f' . 'an_' . $module)
90100
];
91101
}
92102
return $result;

Model/SetLinvFlag.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ public function __construct(
4040
/**
4141
* @param $module
4242
* @param $value
43+
* @param $errorMessage
4344
* @return void
4445
*/
45-
public function execute($module, $value)
46+
public function execute($module, $value, $errorMessage = '')
4647
{
47-
$this->configWriter->save($module . '/g'.'en'.'er'.'al'.'/l'.'in'.'v', $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
48+
$path = $module . '/g'.'en'.'er'.'al'.'/';
49+
$this->configWriter->save($path . 'l'.'in'.'v', $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
50+
$this->configWriter->save($path . 'l'.'in'.'v'.'_'.'error_me'.'ss'.'ag'.'e', $errorMessage, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
4851
$this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER);
4952
}
5053
}

Observer/ConfigObserver.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,29 @@ final public function execute(\Magento\Framework\Event\Observer $observer)
104104
}
105105
return;
106106
}
107-
$module = $section->getName();
108107
$data = $this->info->load([$section]);
109108

110109
if (!$section->validate($data)) {
111110
$groups['general']['fields']['enabled']['value'] = 0;
112-
$this->setLinvFlag->execute($module, 1);
111+
$errorMessage = $data[$section->getModule() . '_errorMsg'] ?? '';
112+
$this->setLinvFlag->execute($section->getName(), 1, $errorMessage);
113113
$request->setPostValue('groups', $groups);
114114

115-
$this->messageManager->addError(
116-
implode(array_reverse(
115+
116+
if (!$errorMessage) {
117+
$errorMessage = implode(array_reverse(
117118
[
118119
'.','d','e','l','b','a','s','i','d',' ','y','l','l','a','c','i','t','a','m',
119120
'o','t','u','a',' ','n','e','e','b',' ','s','a','h',' ','n','o','i','s','n',
120121
'e','t','x','e',' ','e','h','T',' ','.','d','i','l','a','v','n','i',' ','r',
121122
'o',' ','y','t','p','m','e',' ','s','i',' ','y','e','K',' ','t','c','u','d',
122123
'o','r','P'
123124
]
124-
))
125-
);
125+
));
126+
}
127+
$this->messageManager->addError($errorMessage);
126128
} else {
127-
$this->setLinvFlag->execute($module, 0);
129+
$this->setLinvFlag->execute($section->getName(), 0);
128130
}
129131
}
130132
}

view/adminhtml/templates/linv.phtml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,37 @@
1010
*
1111
* @var $block \Magefan\Community\Block\Adminhtml\Linv
1212
*/
13+
$disabledItems = $block->getItems();
14+
$messages = $block->getMessages();
1315
?>
14-
<?php if ($items = $block->getItems()) { ?>
15-
16+
<?php if ($disabledItems || $messages) { ?>
1617
<div class="messages">
1718
<div class="message message-notice notice" style="margin: 20px 3rem;">
1819
<div data-ui-id="messages-message-notice" class="linv">
19-
<?= 'Important! So' . 'me ' . 'Mag'.'efan'.' Ex'.'tensions'.' a'.'re'.' dis'.'abl'.'ed d'.'ue '.'to i'.'nva'.'lid'.' Product K'.'ey: ' ?>
20+
<?= 'Important!' ?>
2021
<div style="margin-left: 30px">
2122
<br/>
2223
<ul>
23-
<?php foreach ($items as $key => $name) { ?>
24+
<?php foreach ($disabledItems as $key => $name) { ?>
2425
<li>
25-
<?= $block->escapeHtml($result = preg_replace('/([A-Z])/', ' $1', $name)); ?>
26+
Mag<span></span>efan <?= $block->escapeHtml($result = preg_replace('/([A-Z])/', ' $1', $name)); ?>:
27+
<?php if (isset($messages[$name])) { ?>
28+
<?= $block->escapeHtml($messages[$name]) ?>
29+
<?php unset($messages[$name]) ?>
30+
<?php } else { ?>
31+
<?= ' dis'.'abl'.'ed d'.'ue '.'to i'.'nva'.'lid'.' Product K'.'ey.' ?>
32+
<?php } ?>
33+
</li>
34+
<?php } ?>
35+
<?php foreach ($messages as $name => $message) { ?>
36+
<li>
37+
<?= 'Mag'.'efan'.' '. $block->escapeHtml( preg_replace('/([A-Z])/', ' $1', $name)) .': ' .$block->escapeQuote($message) ?>
2638
</li>
2739
<?php } ?>
2840
</ul>
2941
</div>
30-
<?= 'Ple' . 'ase che' . 'ck exten' . 'sions config' . 'uration' ?>.
42+
<?= 'Ple' . 'ase che' . 'ck exten' . 'sion(s) config' . 'uration' ?>.
3143
</div>
3244
</div>
3345
</div>
34-
3546
<?php } ?>

0 commit comments

Comments
 (0)