]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Рефактор marketplace products origin/feature_smirnov_2024_11_15_refactor_marketplace_products
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 15 Nov 2024 08:32:55 +0000 (11:32 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 15 Nov 2024 08:32:55 +0000 (11:32 +0300)
erp24/actions/marketplace/PriorityAction.php
erp24/api2/controllers/YandexMarketController.php
erp24/controllers/MatrixErpController.php
erp24/services/MarketplaceService.php

index 391abb7951ae9a29225d42699561e8bae2f8f058..0fe7a177eef760b576670b52efd95bc609b2b297 100644 (file)
@@ -4,11 +4,9 @@ namespace yii_app\actions\marketplace;
 
 use Yii;
 use yii\base\Action;
-use yii\helpers\ArrayHelper;
 use yii\helpers\Json;
 use yii_app\records\MarketplacePriority;
-use yii_app\records\Products1c;
-use yii_app\records\ProductsClass;
+use yii_app\services\MarketplaceService;
 
 class PriorityAction extends Action
 {
@@ -37,10 +35,7 @@ class PriorityAction extends Action
             return 'ok ' . $guid . ' ' . $paramName . ' ' . $value;
         }
 
-        $productsClass = ArrayHelper::getColumn(ProductsClass::find()->where([
-            'tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]
-        ])->all(), 'category_id');
-        $products = ArrayHelper::map(Products1c::find()->where(['parent_id' => $productsClass])->all(), 'id', 'name');
+        $products = MarketplaceService::getMarketplaceProducts();
 
         $marketplacePriorityMap = [];
         foreach (MarketplacePriority::find()->all() as $mp) {
index e49f85b1244fc1506a5d75d32d8c753f4116db3f..5a51dcebd914603fbbb5a3102c7267a85df9e6b0 100644 (file)
@@ -11,7 +11,7 @@ use OpenAPI\Client\Model;
 use GuzzleHttp;
 use yii_app\records\MatrixErp;
 use yii_app\records\Products1c;
-use yii_app\records\ProductsClass;
+use yii_app\services\MarketplaceService;
 
 class YandexMarketController extends Controller
 {
@@ -81,8 +81,8 @@ class YandexMarketController extends Controller
 //        ];
 //        return $apiInstance->updateStocks(109969229, $update_stocks_request);
 
-        $products = Products1c::find()->alias('p')->leftJoin('products_class pc', 'p.parent_id = pc.category_id')
-            ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])->all();
+        $products = MarketplaceService::getMarketplaceProducts();
+
         $matrixErp = MatrixErp::find()->where(['guid' => ArrayHelper::getColumn($products, 'id')])->all();
         $matrixErpByGuid = [];
         foreach ($matrixErp as $matrix) {
index 5c3f269cc8ce3b0dc7ebec86ea5b34f319178821..2c2cd193d169ff8856666d128d485e5714797b0b 100644 (file)
@@ -4,7 +4,6 @@ namespace app\controllers;
 
 use Yii;
 use yii\base\DynamicModel;
-use yii\helpers\ArrayHelper;
 use yii\helpers\Json;
 use yii_app\records\MatrixErp;
 use yii_app\records\MatrixErpMedia;
@@ -14,7 +13,7 @@ use yii\web\Controller;
 use yii\web\NotFoundHttpException;
 use yii\filters\VerbFilter;
 use yii_app\records\Products1c;
-use yii_app\records\ProductsClass;
+use yii_app\services\MarketplaceService;
 
 /**
  * MatrixErpController implements the CRUD actions for MatrixErp model.
@@ -47,10 +46,7 @@ class MatrixErpController extends Controller
             $existingMapGuidGroupNames[$existing->guid][] = $existing->group_name;
         };
 
-        $productsClass = ArrayHelper::getColumn(ProductsClass::find()->where([
-            'tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]
-        ])->all(), 'category_id');
-        $products = Products1c::find()->where(['parent_id' => $productsClass])->all();
+        $products = MarketplaceService::getMarketplaceProducts();
 
         $newCnt = 0;
         foreach ($products as $product) {
index d663a559bac67465cbb75807e897e8ac53707503..9c9f5a4a904d6151290fda04281c254d71f7264d 100644 (file)
@@ -259,7 +259,17 @@ class MarketplaceService
         return $distribution;
     }
 
+    public static function getMarketplaceProducts() {
+        $productsGroup = ProductsClass::find()
+            ->where(['tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])
+            ->select('category_id')
+            ->asArray()
+            ->column();
+
+        $products = Products1c::find()->where(['parent_id' => $productsGroup])->all();
 
+        return $products;
+    }
     /**
      * Статический метод для получения всей информации по продуктам, которая необходима для создания фида.
      *