From 1e69e1db539279256f59d93880fa2572f2996eb0 Mon Sep 17 00:00:00 2001 From: fomichev Date: Mon, 28 Oct 2024 09:58:01 +0300 Subject: [PATCH] =?utf8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?utf8?q?=D0=9B=D0=BE=D0=B3=D0=B8=20=D0=BD=D0=B0=20=D0=BD=D1=83=D0=BB?= =?utf8?q?=D0=B5=D0=B2=D1=83=D1=8E=20=D1=86=D0=B5=D0=BD=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/MarketplaceService.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/erp24/services/MarketplaceService.php b/erp24/services/MarketplaceService.php index 8005f4bb..ba9dc95f 100644 --- a/erp24/services/MarketplaceService.php +++ b/erp24/services/MarketplaceService.php @@ -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 'Описание'; } -- 2.39.5