]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Добавил Логи на нулевую цену
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 28 Oct 2024 06:58:01 +0000 (09:58 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 28 Oct 2024 06:58:01 +0000 (09:58 +0300)
erp24/services/MarketplaceService.php

index 8005f4bb5ee21118a5c42b00ac2b0f2f27a5c177..ba9dc95fdd66fff12dc231c226c2e4f19c25c42e 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace yii_app\services;
 
+use Yii;
 use yii_app\records\Prices;
 use yii_app\records\Products1c;
 use yii_app\records\ProductsClass;
@@ -15,26 +16,40 @@ class MarketplaceService
      */
     public static function getAllProductsInfo($id)
     {
-
         $parents = ProductsClass::find()
             ->select('category_id')
             ->where(['tip' => 'marketplace'])
             ->column();
 
-
         $products = Products1c::find()
             ->where(['tip' => 'products'])
             ->andWhere(['not', ['components' => '']])
             ->andWhere(['parent_id' => $parents])
             ->all();
 
-
         $count = (int)$id;
         $selectedProducts = array_slice($products, 0, $count);
 
         $result = [];
 
         foreach ($selectedProducts as $product) {
+            $price = self::getProductPrice($product->id);
+
+            // Логируем ошибку и пропускаем продукт, если цена равна 0
+            if ($price == 0) {
+                $message = "Product ID {$product->id} has zero price and will be excluded from the feed.";
+                Yii::error($message, __METHOD__);
+
+                // Запись ошибки в таблицу InfoLogs
+                InfoLogService::setInfoLog(
+                    __FILE__,
+                    __LINE__,
+                    $message,
+                    'Zero price error'
+                );
+                continue; // пропускаем продукт
+            }
+
             $components = json_decode($product->components, true);
             $composition = [];
 
@@ -53,7 +68,7 @@ class MarketplaceService
                 'id' => $product->id,
                 'name' => $product->name,
                 'pictures' => self::getProductPictureUrl($product->id),
-                'price' => self::getProductPrice($product->id),
+                'price' => $price,
                 'oldprice' => self::getProductOldPrice($product->id),
                 'description' => self::getProductDescription($product->id),
                 'qty' => self::getProductQty($product->id),
@@ -221,7 +236,7 @@ class MarketplaceService
         $price = Prices::find()
             ->where(['product_id' => $productId])
             ->one();
-            return $price['price'] ?? 10;
+            return $price['price'] ?? 0;
     }
     private static function getProductOldPrice($productId) { return 300; }
     private static function getProductDescription($productId) { return 'Описание'; }