]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-148] вывод отправляемых на маркет данных в отдельном url
authorAlexander Smirnov <fredeom@mail.ru>
Thu, 14 Nov 2024 07:16:41 +0000 (10:16 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Thu, 14 Nov 2024 07:16:41 +0000 (10:16 +0300)
erp24/api2/controllers/YandexMarketController.php
erp24/controllers/YandexMarketController.php [new file with mode: 0644]
erp24/helpers/ImageHelper.php
erp24/views/matrix_erp/index.php
erp24/views/yandex-market/view-cards.php [new file with mode: 0644]

index b7973d830db2c43f2c7969221013c2888f67f19c..c9024a603023446c1cebaecbb7717b67fd9980e3 100644 (file)
@@ -93,12 +93,11 @@ class YandexMarketController extends Controller
             $matrixErpByGuid[$matrix->guid] = $matrix;
         }
         $models = [];
-//        $viewModels = [];
-        if (!$do) {
-            $output .= "<table border='1'><thead><tr><th>offerId</th><th>Категория</th><th>marketCategoryId</th>" .
-                "<th>Название</th><th>Базовая Цена, р</th><th>Бренд</th><th>Длина, см</th><th>Высота, см</th>" .
-                "<th>Ширина, см</th><th>Вес, кг</th><th>Картинка</th><th>Описание</th></tr></thead><tbody>";
-        }
+//        if (!$do) {
+//            $output .= "<table border='1'><thead><tr><th>offerId</th><th>Категория</th><th>marketCategoryId</th>" .
+//                "<th>Название</th><th>Базовая Цена, р</th><th>Бренд</th><th>Длина, см</th><th>Высота, см</th>" .
+//                "<th>Ширина, см</th><th>Вес, кг</th><th>Картинка</th><th>Описание</th></tr></thead><tbody>";
+//        }
         foreach ($products as $product) {
             /* @var $product Products1c */
             if (($matrixErpByGuid[$product->id]->price->price ?? 0) == 0) {
@@ -130,31 +129,16 @@ class YandexMarketController extends Controller
             if ($do) {
                 $models [] = new Model\UpdateOfferMappingDTO($model);
             } else {
-                $output .= "<tr><td>" . $product->id . "</td><td>Цветы</td><td>91284</td><td>" .
-                    (!empty($matrixErpByGuid[$product->id]->matrixProperty->display_name) ?
-                    $matrixErpByGuid[$product->id]->matrixProperty->display_name : $product->name) . "</td><td>"
-                    . $matrixErpByGuid[$product->id]->price->price . "</td><td>База Цветов 24</td><td>" .
-                    ($matrixErpByGuid[$product->id]->matrixProperty->length ?? 23) . "</td><td>" .
-                    ($matrixErpByGuid[$product->id]->matrixProperty->height ?? 40) . "</td><td>" .
-                    ($matrixErpByGuid[$product->id]->matrixProperty->width ?? 20) . "</td><td>" .
-                    ($matrixErpByGuid[$product->id]->matrixProperty->weight ?? 0.15) . "</td><td>" .
-                    ('https://media.erp-flowers.ru/media/view-image/' . ($matrixErpByGuid[$product->id]->matrixProperty->image_id ?? null)) . "</td><td>" .
-                    ($matrixErpByGuid[$product->id]->matrixProperty->description ?? '-') . "</td></tr>";
-//                $viewModels [] = [
-//                    'offerId' => $product->id,
-//                    'category' => 'Цветы',
-//                    'marketCategoryId' => 91284,
-//                    'name' => (!empty($matrixErpByGuid[$product->id]->matrixProperty->display_name) ?
-//                        $matrixErpByGuid[$product->id]->matrixProperty->display_name : $product->name),
-//                    'price' => $matrixErpByGuid[$product->id]->price->price,
-//                    'vendor' => 'База Цветов 24',
-//                    'length' => ($matrixErpByGuid[$product->id]->matrixProperty->length ?? 23),
-//                    'height' => ($matrixErpByGuid[$product->id]->matrixProperty->height ?? 40),
-//                    'width' => ($matrixErpByGuid[$product->id]->matrixProperty->width ?? 20),
-//                    'weight' => ($matrixErpByGuid[$product->id]->matrixProperty->weight ?? 0.15),
-//                    'picture' => ('https://media.erp-flowers.ru/media/view-image/' . ($matrixErpByGuid[$product->id]->matrixProperty->image_id ?? null)),
-//                    'description' => ($matrixErpByGuid[$product->id]->matrixProperty->description ?? '-'),
-//                ];
+//                $output .= "<tr><td>" . $product->id . "</td><td>Цветы</td><td>91284</td><td>" .
+//                    (!empty($matrixErpByGuid[$product->id]->matrixProperty->display_name) ?
+//                    $matrixErpByGuid[$product->id]->matrixProperty->display_name : $product->name) . "</td><td>"
+//                    . $matrixErpByGuid[$product->id]->price->price . "</td><td>База Цветов 24</td><td>" .
+//                    ($matrixErpByGuid[$product->id]->matrixProperty->length ?? 23) . "</td><td>" .
+//                    ($matrixErpByGuid[$product->id]->matrixProperty->height ?? 40) . "</td><td>" .
+//                    ($matrixErpByGuid[$product->id]->matrixProperty->width ?? 20) . "</td><td>" .
+//                    ($matrixErpByGuid[$product->id]->matrixProperty->weight ?? 0.15) . "</td><td>" .
+//                    ('https://media.erp-flowers.ru/media/view-image/' . ($matrixErpByGuid[$product->id]->matrixProperty->image_id ?? null)) . "</td><td>" .
+//                    ($matrixErpByGuid[$product->id]->matrixProperty->description ?? '-') . "</td></tr>";
             }
         }
 
@@ -167,28 +151,10 @@ class YandexMarketController extends Controller
             var_dump($apiInstance->updateoffermappings(5330887, $apiModel));
             $output .= ob_get_clean();
         } else {
-            $output .= '</tbody></table>';
-//            $output .= GridView::widget([
-//                    'dataProvider' => $viewModels,
-//                    'columns' => [
-//                        ['class' => 'yii\grid\SerialColumn'],
-//                        'offerId',
-//                        'category',
-//                        'marketCategoryId',
-//                        'name',
-//                        'price',
-//                        'vendor',
-//                        'length',
-//                        'height',
-//                        'width',
-//                        'weight',
-//                        'picture',
-//                        'description',
-//                    ],
-//                ]);
+//            $output .= '</tbody></table>';
         }
 
-        return "<a href='/yandex-market/create-cards'>Обновить страницу</a>" . str_repeat("&nbsp", 15) .
+        return "<a href='https://erp.erp-flowers.ru/yandex-market/view-cards'>Обновить страницу</a>" . str_repeat("&nbsp", 15) .
                "<a href='/yandex-market/create-cards?do=1'>Отослать данные</a> <br> $output";
     }
 }
\ No newline at end of file
diff --git a/erp24/controllers/YandexMarketController.php b/erp24/controllers/YandexMarketController.php
new file mode 100644 (file)
index 0000000..11b931e
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+
+namespace app\controllers;
+
+use yii\data\ActiveDataProvider;
+use yii\data\ArrayDataProvider;
+use yii\grid\GridView;
+use yii\helpers\ArrayHelper;
+use yii\web\Controller;
+use yii_app\helpers\ImageHelper;
+use yii_app\records\MatrixErp;
+use yii_app\records\Products1c;
+use yii_app\records\ProductsClass;
+use OpenAPI\Client\Model;
+
+class YandexMarketController extends Controller
+{
+    public function actionViewCards() {
+        $products = Products1c::find()->alias('p')->leftJoin('products_class pc', 'p.parent_id = pc.category_id')
+            ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])->all();
+        $matrixErp = MatrixErp::find()->where(['guid' => ArrayHelper::getColumn($products, 'id')])->all();
+        $matrixErpByGuid = [];
+        foreach ($matrixErp as $matrix) {
+            /* @var $matrix MatrixErp */
+            $matrixErpByGuid[$matrix->guid] = $matrix;
+        }
+
+        $viewModels = [];
+        foreach ($products as $product) {
+            /* @var $product Products1c */
+            if (($matrixErpByGuid[$product->id]->price->price ?? 0) == 0) {
+                continue;
+            }
+            $model = [
+                'offer' => [
+                    'offerId' => $product->id,
+                    'category' => 'Цветы',
+                    'marketCategoryId' => '91284',
+                    'name' => !empty($matrixErpByGuid[$product->id]->matrixProperty->display_name) ?
+                        $matrixErpByGuid[$product->id]->matrixProperty->display_name : $product->name,
+                    'basicPrice' => [
+                        'currencyId' => Model\CurrencyType::RUR,
+                        'value' => $matrixErpByGuid[$product->id]->price->price,
+                    ],
+                    'vendor' => 'База Цветов 24',
+                    'weightDimensions' => new Model\OfferWeightDimensionsDTO([
+                        'length' => $matrixErpByGuid[$product->id]->matrixProperty->length ?? 23,
+                        'height' => $matrixErpByGuid[$product->id]->matrixProperty->height ?? 40,
+                        'width' => $matrixErpByGuid[$product->id]->matrixProperty->width ?? 20,
+                        'weight' => $matrixErpByGuid[$product->id]->matrixProperty->weight ?? 0.15,
+                    ]),
+                    'pictures' => ['https://media.erp-flowers.ru/media/view-image/' . ($matrixErpByGuid[$product->id]->matrixProperty->image_id ?? null)],
+                    'description' => $matrixErpByGuid[$product->id]->matrixProperty->description ?? '-',
+                ],
+            ];
+
+            $viewModels [] = [
+                'offerId' => $product->id,
+                'category' => 'Цветы',
+                'marketCategoryId' => 91284,
+                'name' => (!empty($matrixErpByGuid[$product->id]->matrixProperty->display_name) ?
+                    $matrixErpByGuid[$product->id]->matrixProperty->display_name : $product->name),
+                'price' => $matrixErpByGuid[$product->id]->price->price,
+                'vendor' => 'База Цветов 24',
+                'length' => ($matrixErpByGuid[$product->id]->matrixProperty->length ?? 23),
+                'height' => ($matrixErpByGuid[$product->id]->matrixProperty->height ?? 40),
+                'width' => ($matrixErpByGuid[$product->id]->matrixProperty->width ?? 20),
+                'weight' => ($matrixErpByGuid[$product->id]->matrixProperty->weight ?? 0.15),
+                'picture' => ('https://media.erp-flowers.ru/media/view-image/' . ($matrixErpByGuid[$product->id]->matrixProperty->image_id ?? null)),
+                'description' => ($matrixErpByGuid[$product->id]->matrixProperty->description ?? '-'),
+            ];
+        }
+        $output = GridView::widget([
+            'dataProvider' => new ArrayDataProvider(['allModels' => $viewModels]),
+            'columns' => [
+                ['class' => 'yii\grid\SerialColumn'],
+                'offerId',
+                [
+                    'attribute' => 'category',
+                    'label' => 'Категория',
+                ],
+                'marketCategoryId',
+                [
+                    'attribute' => 'name',
+                    'label' => 'Название',
+                ],
+                [
+                    'attribute' => 'price',
+                    'label' => 'Цена',
+                ],
+                [
+                    'attribute' => 'vendor',
+                    'label' => 'Бренд',
+                ],
+                [
+                    'attribute' => 'length',
+                    'label' => 'Длина, см',
+                ],
+                [
+                    'attribute' => 'height',
+                    'label' => 'Высота, см',
+                ],
+                [
+                    'attribute' => 'width',
+                    'label' => 'Ширина, см',
+                ],
+                [
+                    'attribute' => 'weight',
+                    'label' => 'Вес, кг',
+                ],
+                [
+                    'attribute' => 'picture',
+                    'label' => 'Изображение',
+                    'format' => 'raw',
+                    'value' => function ($model) {
+                        ob_start();
+                        ImageHelper::drawImage($model['picture']);
+                        return ob_get_clean();
+                    }
+                ],
+                [
+                    'attribute' => 'description',
+                    'label' => 'Описание',
+                ],
+            ],
+        ]);
+        return $this->render('view-cards', compact('output'));
+    }
+}
\ No newline at end of file
index afd3c7548595a31145442dc4ba240a125cf812f3..0dac85fd3a58b28c49ec7c8351902c7cda434c58 100644 (file)
@@ -25,7 +25,7 @@ class ImageHelper
 
        
     public static function drawImage($url, $width = 200) {
-        ?><img width=<?= $width ?> src='<?= FileService::padWithSlash($url) ?>' alt="img" onclick="window.open(this.src, '_blank');" /><?php
+        ?><img width=<?= $width ?> src='<?= str_starts_with($url, 'http') ? $url : FileService::padWithSlash($url) ?>' alt="img" onclick="window.open(this.src, '_blank');" /><?php
     }
 
 
index 9a78f5eac7cc64968ea9439b159ba6b7228ae1a9..6ea0a16e8be6ce884db316c686ad24107edf90d6 100644 (file)
@@ -73,7 +73,7 @@ $this->params['breadcrumbs'][] = $this->title;
     <div class="row mb-4">
         <div class="col-12">
             <?= Html::a("Создать карточки для яндекс-маркетплейса",
-                'https://api2.erp.erp-flowers.ru/yandex-market/create-cards',
+                'https://erp.erp-flowers.ru/yandex-market/view-cards',
                 ['class' => 'btn btn-primary', 'target' => '_blank']
             ) ?>
         </div>
diff --git a/erp24/views/yandex-market/view-cards.php b/erp24/views/yandex-market/view-cards.php
new file mode 100644 (file)
index 0000000..14368fb
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+/* @var $output string */
+
+?>
+
+<a href='/yandex-market/view-cards' class="btn btn-link">Обновить страницу</a><?= str_repeat("&nbsp", 15) ?>
+<a href='https://api2.erp.erp-flowers.ru/yandex-market/create-cards?do=1' class="btn btn-link">Отослать данные</a> <br>
+
+<?= $output ?>
+