$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) {
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>";
}
}
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(" ", 15) .
+ return "<a href='https://erp.erp-flowers.ru/yandex-market/view-cards'>Обновить страницу</a>" . str_repeat(" ", 15) .
"<a href='/yandex-market/create-cards?do=1'>Отослать данные</a> <br> $output";
}
}
\ No newline at end of file
--- /dev/null
+<?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