feat(app): add maintenance mode
This commit is contained in:
@@ -1,5 +1,19 @@
|
|||||||
<?php
|
<?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
|
class ControllerExtensionModuleTgshop extends Controller
|
||||||
{
|
{
|
||||||
private static array $themes = [
|
private static array $themes = [
|
||||||
@@ -40,9 +54,9 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
'silk' => 'Шёлк (silk)',
|
'silk' => 'Шёлк (silk)',
|
||||||
];
|
];
|
||||||
|
|
||||||
private $error = array();
|
private array $error = [];
|
||||||
|
|
||||||
public function index()
|
public function index(): void
|
||||||
{
|
{
|
||||||
$this->load->language('extension/module/tgshop');
|
$this->load->language('extension/module/tgshop');
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
@@ -83,9 +97,9 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$data['settings'] = static::$settings;
|
$data['settings'] = static::getSettingsConfig();
|
||||||
|
|
||||||
foreach (static::$settings as $configs) {
|
foreach ($data['settings'] as $configs) {
|
||||||
foreach ($configs as $key => $config) {
|
foreach ($configs as $key => $config) {
|
||||||
if ($config['type'] === 'image') {
|
if ($config['type'] === 'image') {
|
||||||
$this->load->model('tool/image');
|
$this->load->model('tool/image');
|
||||||
@@ -99,6 +113,7 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
} elseif ($config['type'] === 'products') {
|
} elseif ($config['type'] === 'products') {
|
||||||
$products = $this->request->post[$key] ?? $this->config->get($key) ?? [];
|
$products = $this->request->post[$key] ?? $this->config->get($key) ?? [];
|
||||||
$this->load->model('catalog/product');
|
$this->load->model('catalog/product');
|
||||||
|
$data[$key] = [];
|
||||||
foreach ($products as $productId) {
|
foreach ($products as $productId) {
|
||||||
$productItem = $this->model_catalog_product->getProduct($productId);
|
$productItem = $this->model_catalog_product->getProduct($productId);
|
||||||
$data[$key][] = [
|
$data[$key][] = [
|
||||||
@@ -106,15 +121,13 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
'name' => $productItem['name'],
|
'name' => $productItem['name'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
} else {
|
} elseif (isset($this->request->post[$key])) {
|
||||||
if (isset($this->request->post[$key])) {
|
|
||||||
$data[$key] = $this->request->post[$key];
|
$data[$key] = $this->request->post[$key];
|
||||||
} else {
|
} else {
|
||||||
$data[$key] = $this->config->get($key);
|
$data[$key] = $this->config->get($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->response->setOutput($this->load->view('extension/module/tgshop', $data));
|
$this->response->setOutput($this->load->view('extension/module/tgshop', $data));
|
||||||
}
|
}
|
||||||
@@ -146,13 +159,13 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
$this->response->setOutput($this->load->view('extension/module/tgshop_init', $data));
|
$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')) {
|
if (! $this->user->hasPermission('modify', 'extension/module/tgshop')) {
|
||||||
$this->error['error_warning'] = $this->language->get('error_permission');
|
$this->error['error_warning'] = $this->language->get('error_permission');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (static::$settings as $configs) {
|
foreach (static::getSettingsConfig() as $configs) {
|
||||||
foreach ($configs as $key => $config) {
|
foreach ($configs as $key => $config) {
|
||||||
if (($config['required'] ?? false) === true && ! $this->request->post[$key]) {
|
if (($config['required'] ?? false) === true && ! $this->request->post[$key]) {
|
||||||
$this->error["error_$key"] = 'Поле "' . $this->language->get(
|
$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 [
|
return [
|
||||||
'general' => [
|
'general' => [
|
||||||
@@ -245,7 +258,7 @@ class ControllerExtensionModuleTgshop extends Controller
|
|||||||
0 => 'Выключено',
|
0 => 'Выключено',
|
||||||
1 => 'Включено',
|
1 => 'Включено',
|
||||||
],
|
],
|
||||||
'help' => '',
|
'help' => 'Если выключено, покупатели в Telegram увидят сообщение, что магазин временно закрыт. Заказы и просмотр товаров будут недоступны.',
|
||||||
],
|
],
|
||||||
|
|
||||||
'module_tgshop_app_name' => [
|
'module_tgshop_app_name' => [
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ if (is_readable($sysLibPath . '/oc_telegram_shop.phar')) {
|
|||||||
throw new RuntimeException('Unable to locate bulk products directory.');
|
throw new RuntimeException('Unable to locate bulk products directory.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property Config $config
|
||||||
|
*/
|
||||||
class Controllerextensiontgshophandle extends Controller
|
class Controllerextensiontgshophandle extends Controller
|
||||||
{
|
{
|
||||||
public function index(): void
|
public function index(): void
|
||||||
{
|
{
|
||||||
$app = ApplicationFactory::create([
|
$app = ApplicationFactory::create([
|
||||||
|
'app_enabled' => filter_var($this->config->get('module_tgshop_status'), FILTER_VALIDATE_BOOLEAN),
|
||||||
'oc_config_tax' => $this->config->get('config_tax'),
|
'oc_config_tax' => $this->config->get('config_tax'),
|
||||||
'oc_default_currency' => $this->config->get('config_currency'),
|
'oc_default_currency' => $this->config->get('config_currency'),
|
||||||
// ID группы покупателей, которая будет использоаваться в заказах через Телеграм.
|
// ID группы покупателей, которая будет использоаваться в заказах через Телеграм.
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Handlers;
|
|
||||||
|
|
||||||
use Openguru\OpenCartFramework\Http\JsonResponse;
|
|
||||||
use Openguru\OpenCartFramework\QueryBuilder\Builder;
|
|
||||||
use Openguru\OpenCartFramework\QueryBuilder\JoinClause;
|
|
||||||
|
|
||||||
class HelloWorldHandler
|
|
||||||
{
|
|
||||||
private Builder $queryBuilder;
|
|
||||||
|
|
||||||
public function __construct(Builder $queryBuilder)
|
|
||||||
{
|
|
||||||
$this->queryBuilder = $queryBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle(): JsonResponse
|
|
||||||
{
|
|
||||||
$languageId = 1;
|
|
||||||
|
|
||||||
$products = $this->queryBuilder->newQuery()
|
|
||||||
->select([
|
|
||||||
'products.product_id' => 'product_id',
|
|
||||||
'products.quantity' => 'product_quantity',
|
|
||||||
'product_description.name' => 'product_name',
|
|
||||||
'products.price' => 'product_price',
|
|
||||||
])
|
|
||||||
->from(db_table('product'), 'products')
|
|
||||||
->join(
|
|
||||||
db_table('product_description') . ' AS product_description',
|
|
||||||
function (JoinClause $join) use ($languageId) {
|
|
||||||
$join->on('products.product_id', '=', 'product_description.product_id')
|
|
||||||
->where('product_description.language_id', '=', $languageId);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return new JsonResponse([
|
|
||||||
'data' => array_map(function ($product) {
|
|
||||||
return [
|
|
||||||
'product_id' => (int) $product['product_id'],
|
|
||||||
'product_quantity' => (int) $product['product_quantity'],
|
|
||||||
'product_name' => $product['product_name'],
|
|
||||||
'product_price' => (float) $product['product_price'],
|
|
||||||
];
|
|
||||||
}, $products),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -46,6 +46,7 @@ class SettingsHandler
|
|||||||
'theme_light' => $this->settings->get('theme_light'),
|
'theme_light' => $this->settings->get('theme_light'),
|
||||||
'theme_dark' => $this->settings->get('theme_dark'),
|
'theme_dark' => $this->settings->get('theme_dark'),
|
||||||
'ya_metrika_enabled' => $this->settings->get('ya_metrika_enabled'),
|
'ya_metrika_enabled' => $this->settings->get('ya_metrika_enabled'),
|
||||||
|
'app_enabled' => $this->settings->get('app_enabled'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ categoriesStore.fetchTopCategories();
|
|||||||
categoriesStore.fetchCategories();
|
categoriesStore.fetchCategories();
|
||||||
|
|
||||||
settings.load()
|
settings.load()
|
||||||
|
.then(() => {
|
||||||
|
if (settings.app_enabled === false) {
|
||||||
|
throw new Error('App disabled (maintenance mode)');
|
||||||
|
}
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
document.documentElement.setAttribute('data-theme', settings.theme[window.Telegram.WebApp.colorScheme]);
|
document.documentElement.setAttribute('data-theme', settings.theme[window.Telegram.WebApp.colorScheme]);
|
||||||
if (settings.night_auto) {
|
if (settings.night_auto) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {fetchSettings} from "@/utils/ftch.js";
|
|||||||
|
|
||||||
export const useSettingsStore = defineStore('settings', {
|
export const useSettingsStore = defineStore('settings', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
app_enabled: true,
|
||||||
app_name: 'OpenCart Telegram магазин',
|
app_name: 'OpenCart Telegram магазин',
|
||||||
app_icon: '',
|
app_icon: '',
|
||||||
app_icon192: '',
|
app_icon192: '',
|
||||||
@@ -32,6 +33,7 @@ export const useSettingsStore = defineStore('settings', {
|
|||||||
this.theme.light = settings.theme_light;
|
this.theme.light = settings.theme_light;
|
||||||
this.theme.dark = settings.theme_dark;
|
this.theme.dark = settings.theme_dark;
|
||||||
this.ya_metrika_enabled = settings.ya_metrika_enabled;
|
this.ya_metrika_enabled = settings.ya_metrika_enabled;
|
||||||
|
this.app_enabled = settings.app_enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user