namespace yii_app\services;
+use Yii;
use yii_app\records\Prices;
use yii_app\records\Products1c;
use yii_app\records\ProductsClass;
*/
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 = [];
'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),
$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 'Описание'; }