]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Цены в MatrixErpController.php
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 09:12:31 +0000 (12:12 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 09:12:31 +0000 (12:12 +0300)
erp24/controllers/MarketplacePricesController.php
erp24/controllers/MatrixErpController.php
erp24/records/MatrixErp.php
erp24/views/matrix_erp/update.php

index d672e186ce4ffc554d16d87562b270259e33b334..106b3a34fdeae96fc5105dff6f1c697ab9d01741 100644 (file)
@@ -167,6 +167,13 @@ class MarketplacePricesController extends Controller
             }
         } else {
             $model->loadDefaultValues();
+            // Предзаполняем модель из GET параметров
+            if (Yii::$app->request->get('matrix_erp_id')) {
+                $model->matrix_erp_id = Yii::$app->request->get('matrix_erp_id');
+            }
+            if (Yii::$app->request->get('marketplace_id')) {
+                $model->marketplace_id = Yii::$app->request->get('marketplace_id');
+            }
         }
 
         // Данные для выпадающих списков
index aec0f9276f88029ee20649101c2f15d9d036199f..18af09c1dc7bb7e1b7338e614db1d262c1c72ed8 100644 (file)
@@ -16,6 +16,7 @@ use yii\helpers\Json;
 use yii\web\UploadedFile;
 use yii_app\records\Files;
 use yii_app\records\Images;
+use yii_app\records\MarketplacePrices;
 use yii_app\records\MatrixErp;
 use yii_app\records\MatrixErpMedia;
 use yii_app\records\MatrixErpProperty;
@@ -247,10 +248,16 @@ class MatrixErpController extends Controller
             [['imageFile',], 'image',],
         ]);
 
+        // Получаем цены для маркетплейсов
+        $marketplacePrices = MarketplacePrices::find()
+            ->where(['matrix_erp_id' => $modelMatrixErp->id])
+            ->all();
+
         return $this->render('/matrix_erp/update', [
             'modelMatrixErp' => $modelMatrixErp,
             'modelMatrixErpProperty' => $modelMatrixErpProperty,
             'filterModel' => $filterModel,
+            'marketplacePrices' => $marketplacePrices,
         ]);
     }
 
index 2d468f7164a0b7c7316c09403bacba418252f94c..be0e23ca9a7678629a0ba0ec14ab9336b68c5d3e 100644 (file)
@@ -7,6 +7,7 @@ use yii\behaviors\TimestampBehavior;
 use yii\db\ActiveQueryInterface;
 use yii\db\Expression;
 use yii_app\helpers\DataHelper;
+use yii_app\records\MarketplacePrices;
 
 /**
  * This is the model class for table "matrix_erp".
@@ -109,6 +110,11 @@ class MatrixErp extends \yii\db\ActiveRecord
         return $this->hasMany(MatrixErpMedia::class, ['guid' => 'guid']);
     }
 
+    public function getMarketplacePrices(): ActiveQueryInterface
+    {
+        return $this->hasMany(MarketplacePrices::class, ['matrix_erp_id' => 'id']);
+    }
+
 
     public function setComponentsArray() : void
     {
index 79b219d13230a3e2427427a93008a97ffc1be120..ca12c9097b617c5772a1d2bcede8c5e170047f61 100644 (file)
@@ -9,6 +9,7 @@ use yii\widgets\DetailView;
 
 /** @var yii_app\records\MatrixErp $modelMatrixErp */
 /** @var yii_app\records\MatrixErpProperty $modelMatrixErpProperty */
+/** @var array $marketplacePrices */
 
 $this->title = 'Изменение свойств матричного букета: ' . $modelMatrixErp->name;
 $this->params['breadcrumbs'][] = ['label' => 'Matrix Erps', 'url' => ['index']];
@@ -30,7 +31,10 @@ $this->params['breadcrumbs'][] = 'Update';
 //            'id',
             'name',
             'articule',
-            'price.price',
+            [
+                'attribute' => 'price.price',
+                'label' => 'Цена 1С',
+            ],
             'group_name',
             'code',
             'guid',
@@ -48,6 +52,49 @@ $this->params['breadcrumbs'][] = 'Update';
 
         ],
     ]) ?>
+
+    <h3 class="mt-4">Цены маркетплейсов</h3>
+    <table class="table table-bordered">
+        <thead>
+            <tr>
+                <th>МП</th>
+                <th>Цена</th>
+                <th>Старая цена</th>
+                <th>Действия</th>
+            </tr>
+        </thead>
+        <tbody>
+            <?php
+            $marketplaces = [
+                1 => 'YM', // Яндекс
+                2 => 'FW', // Флаувау
+            ];
+
+            foreach ($marketplaces as $marketplaceId => $marketplaceAlias) {
+                $priceRecord = null;
+                foreach ($marketplacePrices as $price) {
+                    if ($price->marketplace_id == $marketplaceId) {
+                        $priceRecord = $price;
+                        break;
+                    }
+                }
+                ?>
+                <tr>
+                    <td><?= Html::encode($marketplaceAlias) ?></td>
+                    <td><?= $priceRecord ? Html::encode($priceRecord->price) : '-' ?></td>
+                    <td><?= $priceRecord && $priceRecord->old_price ? Html::encode($priceRecord->old_price) : '-' ?></td>
+                    <td>
+                        <?php if ($priceRecord): ?>
+                            <?= Html::a('Редактировать', ['/marketplace-prices/update', 'id' => $priceRecord->id], ['class' => 'btn btn-sm btn-primary']) ?>
+                        <?php else: ?>
+                            <?= Html::a('Создать', ['/marketplace-prices/create', 'matrix_erp_id' => $modelMatrixErp->id, 'marketplace_id' => $marketplaceId], ['class' => 'btn btn-sm btn-success']) ?>
+                        <?php endif; ?>
+                    </td>
+                </tr>
+            <?php } ?>
+        </tbody>
+    </table>
+
     <span style="display: none">
     <?= DetailView::widget([
         'model' => $modelMatrixErp,