From: Vladimir Fomichev Date: Thu, 2 Oct 2025 12:19:57 +0000 (+0300) Subject: Кнопка активности фида X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=424bfc6d86c6d289d10bb07bdec0bb56c4e767a2;p=erp24_rep%2Fyii-erp24%2F.git Кнопка активности фида --- 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); + ?>