From: fomichev Date: Mon, 28 Oct 2024 06:58:01 +0000 (+0300) Subject: Добавил Логи на нулевую цену X-Git-Tag: 1.6~13^2~25 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=1e69e1db539279256f59d93880fa2572f2996eb0;p=erp24_rep%2Fyii-erp24%2F.git Добавил Логи на нулевую цену --- 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 'Описание'; }