feat(app): add maintenance mode

This commit is contained in:
Nikita Kiselev
2025-08-03 10:00:54 +03:00
parent 86d0fa9594
commit 2752ec3dd1
6 changed files with 38 additions and 63 deletions

View File

@@ -1,5 +1,19 @@
<?php
/**
* @property Document $document
* @property Loader $load
* @property Config $config
* @property Language $language
* @property Request $request
* @property Session $session
* @property ModelSettingSetting $model_setting_setting
* @property Response $response
* @property Url $url
* @property ModelToolImage $model_tool_image
* @property ModelCatalogProduct $model_catalog_product
* @property User $user
*/
class ControllerExtensionModuleTgshop extends Controller
{
private static array $themes = [
@@ -40,9 +54,9 @@ class ControllerExtensionModuleTgshop extends Controller
'silk' => 'Шёлк (silk)',
];
private $error = array();
private array $error = [];
public function index()
public function index(): void
{
$this->load->language('extension/module/tgshop');
$this->load->model('setting/setting');
@@ -83,9 +97,9 @@ class ControllerExtensionModuleTgshop extends Controller
true
);
$data['settings'] = static::$settings;
$data['settings'] = static::getSettingsConfig();
foreach (static::$settings as $configs) {
foreach ($data['settings'] as $configs) {
foreach ($configs as $key => $config) {
if ($config['type'] === 'image') {
$this->load->model('tool/image');
@@ -99,6 +113,7 @@ class ControllerExtensionModuleTgshop extends Controller
} elseif ($config['type'] === 'products') {
$products = $this->request->post[$key] ?? $this->config->get($key) ?? [];
$this->load->model('catalog/product');
$data[$key] = [];
foreach ($products as $productId) {
$productItem = $this->model_catalog_product->getProduct($productId);
$data[$key][] = [
@@ -106,12 +121,10 @@ class ControllerExtensionModuleTgshop extends Controller
'name' => $productItem['name'],
];
}
} elseif (isset($this->request->post[$key])) {
$data[$key] = $this->request->post[$key];
} else {
if (isset($this->request->post[$key])) {
$data[$key] = $this->request->post[$key];
} else {
$data[$key] = $this->config->get($key);
}
$data[$key] = $this->config->get($key);
}
}
}
@@ -146,13 +159,13 @@ class ControllerExtensionModuleTgshop extends Controller
$this->response->setOutput($this->load->view('extension/module/tgshop_init', $data));
}
protected function validate()
protected function validate(): bool
{
if (! $this->user->hasPermission('modify', 'extension/module/tgshop')) {
$this->error['error_warning'] = $this->language->get('error_permission');
}
foreach (static::$settings as $configs) {
foreach (static::getSettingsConfig() as $configs) {
foreach ($configs as $key => $config) {
if (($config['required'] ?? false) === true && ! $this->request->post[$key]) {
$this->error["error_$key"] = 'Поле "' . $this->language->get(
@@ -235,7 +248,7 @@ class ControllerExtensionModuleTgshop extends Controller
];
}
private function getSettingsConfig(): array
private static function getSettingsConfig(): array
{
return [
'general' => [
@@ -245,7 +258,7 @@ class ControllerExtensionModuleTgshop extends Controller
0 => 'Выключено',
1 => 'Включено',
],
'help' => '',
'help' => 'Если выключено, покупатели в Telegram увидят сообщение, что магазин временно закрыт. Заказы и просмотр товаров будут недоступны.',
],
'module_tgshop_app_name' => [