From 424bfc6d86c6d289d10bb07bdec0bb56c4e767a2 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Thu, 2 Oct 2025 15:19:57 +0300 Subject: [PATCH] =?utf8?q?=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20=D0=B0?= =?utf8?q?=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D1=84?= =?utf8?q?=D0=B8=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/MatrixErpController.php | 41 +++++++++++++++++++++++ erp24/views/matrix_erp/index.php | 23 ++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/erp24/controllers/MatrixErpController.php b/erp24/controllers/MatrixErpController.php index c82762b1..d6a15686 100644 --- a/erp24/controllers/MatrixErpController.php +++ b/erp24/controllers/MatrixErpController.php @@ -266,6 +266,47 @@ class MatrixErpController extends Controller return $this->redirect('index'); } + /** + * AJAX экшн для изменения статуса активности фида + * @return \yii\web\Response + */ + public function actionToggleFeedActive() + { + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + + $id = Yii::$app->request->post('id'); + $isFeedActive = Yii::$app->request->post('is_feed_active'); + + if (!$id) { + return [ + 'success' => false, + 'message' => 'ID записи не указан' + ]; + } + + $matrixErp = MatrixErp::findOne($id); + if (!$matrixErp) { + return [ + 'success' => false, + 'message' => 'Запись не найдена' + ]; + } + + $matrixErp->is_feed_active = (int)$isFeedActive; + if ($matrixErp->save()) { + $statusText = $isFeedActive ? 'включена' : 'отключена'; + return [ + 'success' => true, + 'message' => "Активность фида для товара \"{$matrixErp->name}\" {$statusText}" + ]; + } else { + return [ + 'success' => false, + 'message' => 'Ошибка при сохранении: ' . json_encode($matrixErp->getErrors(), JSON_UNESCAPED_UNICODE) + ]; + } + } + /** * Finds the MatrixErp model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/erp24/views/matrix_erp/index.php b/erp24/views/matrix_erp/index.php index 5235e3f8..bfd69a8c 100644 --- a/erp24/views/matrix_erp/index.php +++ b/erp24/views/matrix_erp/index.php @@ -3,6 +3,7 @@ use yii\helpers\ArrayHelper; use yii_app\helpers\ImageHelper; use yii\helpers\Html; +use yii\helpers\Url; use yii\widgets\ActiveForm; use yii_app\services\FileService; @@ -153,6 +154,7 @@ $this->params['breadcrumbs'][] = $this->title; Дата начала актуальности Дата окончания актуальности Активность + Фид товаров @@ -206,11 +208,19 @@ $this->params['breadcrumbs'][] = $this->title; date_from ?> date_to ?> active) ? 'Активна': 'Не активна') ?> + + is_feed_active ? 'checked' : '' ?> + onchange="toggleFeedActive(id ?>, this.checked)" + onclick="event.stopPropagation()"> + active ? $editUrl . "    " . $deleteUrl : '')?> - +
@@ -334,4 +344,15 @@ $this->params['breadcrumbs'][] = $this->title;
+ + +
+ + registerJsFile('@web/js/matrix-erp/index.js', ['depends' => [\yii\web\JqueryAsset::class]]); + $this->registerJs(" + window.csrfToken = '" . Yii::$app->request->csrfToken . "'; + window.matrixErpToggleFeedActiveUrl = '" . Url::to(['matrix-erp/toggle-feed-active']) . "'; + ", \yii\web\View::POS_READY); + ?> -- 2.39.5