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.
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;
<th>Дата начала актуальности</th>
<th>Дата окончания актуальности</th>
<th>Активность</th>
+ <th>Фид товаров</th>
<th></th>
</tr>
</thead>
<td><?= $item->date_from ?></td>
<td><?= $item->date_to ?></td>
<td><?= (($item->active) ? 'Активна': 'Не активна') ?></td>
+ <td>
+ <input type="checkbox"
+ class="feed-active-checkbox"
+ data-id="<?= $item->id ?>"
+ <?= $item->is_feed_active ? 'checked' : '' ?>
+ onchange="toggleFeedActive(<?= $item->id ?>, this.checked)"
+ onclick="event.stopPropagation()">
+ </td>
<td><span style="white-space:nowrap;"><?= ($item->active ? $editUrl . " " . $deleteUrl : '')?></span></td>
</tr>
<tr style="display:none">
- <td colspan="8">
+ <td colspan="11">
<div class="">
<div class="panel panel-primary receipts-inline-table border-0">
<div class="tab-menu-heading p-0 border-0">
</div>
</div>
</div>
+
+ <!-- Alert container -->
+ <div id="feed-alert-container" style="position: fixed; top: 100px; right: 20px; z-index: 9999; max-width: 400px;"></div>
+
+ <?php
+ $this->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);
+ ?>
</div>