--- /dev/null
+<?php
+
+namespace yii_app\actions\marketplace;
+
+use Yii;
+use yii\base\Action;
+use yii\data\ActiveDataProvider;
+use yii\data\ArrayDataProvider;
+use yii_app\records\Products1c;
+use yii_app\records\Products1cNomenclature;
+use yii_app\records\ProductsClass;
+use yii_app\services\MarketplaceService;
+
+class ReportAction extends Action
+{
+ public function run()
+ {
+ $subQuery = Products1c::find()
+ ->alias('p1n')
+ ->leftJoin('products_class pc', 'p1n.id = pc.category_id')
+ ->where(['or',
+ ['pc.tip' => ProductsClass::HINT_MARKETPLACE],
+ ['pc.tip' => ProductsClass::HINT_MARKETPLACE_ADDITIONAL]
+ ])
+ ->select('p1n.id');
+
+ $productsRaw = Products1c::find()
+ ->where(['in', 'parent_id', $subQuery])
+ ->limit(10)
+ ->all();
+
+ $marketplaceService = new MarketplaceService();
+
+ $products = [];
+
+ foreach ($productsRaw as $product) {
+ $check = $marketplaceService->checkProducts($product);
+ $products[] = [
+ 'id' => $product->id,
+ 'name' => $product->name,
+ 'articule' => $product->articule,
+ 'checkResult' => $check !== false ? 'true' : 'false',
+ ];
+ }
+
+
+ $dataProvider = new ArrayDataProvider([
+ 'allModels' => $products,
+ 'pagination' => ['pageSize' => 20],
+ ]);
+
+
+ return $this->controller->render('report', [
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
+}
\ No newline at end of file
}
- public static function getProductsInfoForFeed(int $warehouseGuid, array $storeData)
+ public static function getProductsInfoForFeed(int $warehouseGuid, array $storeData): array
{
-
-
if (!is_array($storeData)) {
Yii::error('Invalid data format for storeData; expected array.', __METHOD__);
return [];
}
$storeGuid = $store->guid;
-
if (!isset($storeData[$storeGuid])) {
Yii::warning("Не найдено данных store GUID {$storeGuid}", __METHOD__);
return [];
}
-
$productQuantities = $storeData[$storeGuid];
-
$products = Products1c::find()
->where(['id' => array_keys($productQuantities)])
->andWhere(['!=', 'components', ''])
$result = [];
foreach ($products as $product) {
- $properties = MarketplaceService::getProductPropertiesByGuid($product->id);
- if (!$properties) {
- $message = "Товар с GUID {$product->id} не имеет свойств в MatrixErpProperty и был исключен из фида.";
- Yii::error($message, __METHOD__);
-
- InfoLogService::setInfoLog(
- __FILE__,
- __LINE__,
- $message,
- 'Missing properties error'
- );
+ $check = self::checkProducts($product);
+ if ($check === false) {
continue;
}
- $price = MarketplaceService::getProductPrice($product->id);
-
- if ($price == 0) {
- $message = "У товара {$product->id} отсутствует цена и он будет исключен из фида.";
- Yii::error($message, __METHOD__);
-
-
- InfoLogService::setInfoLog(
- __FILE__,
- __LINE__,
- $message,
- 'Zero price error'
- );
- continue;
- }
+ $properties = $check['properties'];
+ $price = $check['price'];
$components = json_decode($product->components, true);
$composition = [];
}
}
-
$availableQty = $productQuantities[$product->id] ?? 0;
$result[] = [
return $result;
}
+ public function checkProducts($product): array|false {
+ $properties = MarketplaceService::getProductPropertiesByGuid($product->id);
+ if (!$properties) {
+ $message = "Товар с GUID {$product->id} не имеет свойств в MatrixErpProperty и был исключен из фида.";
+ Yii::error($message, __METHOD__);
+ InfoLogService::setInfoLog(__FILE__, __LINE__, $message, 'Missing properties error');
+ return false;
+ }
+
+ $price = MarketplaceService::getProductPrice($product->id);
+ if ($price == 0) {
+ $message = "У товара {$product->id} отсутствует цена и он будет исключен из фида.";
+ Yii::error($message, __METHOD__);
+ InfoLogService::setInfoLog(__FILE__, __LINE__, $message, 'Zero price error');
+ return false;
+ }
+
+ return [
+ 'properties' => $properties,
+ 'price' => $price,
+ ];
+ }
+
/**
* Статический метод для создания XML-фида на основе информации о продуктах.
*
--- /dev/null
+<?php
+
+use yii\grid\GridView;
+use yii\helpers\Html;
+
+/* @var $this yii\web\View */
+/* @var $dataProvider yii\data\ActiveDataProvider */
+
+$this->title = 'Список продуктов, которые не попадают в фиды';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="marketplace-report p-5">
+
+ <h1><?= Html::encode($this->title) ?></h1>
+
+ <?= GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+ 'name',
+ 'articule',
+ 'id',
+ 'checkResult'
+ ],
+ ]); ?>
+</div>
\ No newline at end of file