}
}
- // var_dump($prices);
+ //var_dump($prices);
// 3. Получение состава букетов
$bouquetComposition = [];
// 4. Проверка остатков
$marketplaceStores = array_column(MarketplaceStore::findAll(['warehouse_id' => $marketId]), null, 'guid');
+
$marketplaceStoresCnt = MarketplaceStore::find()->select(['guid', 'COUNT(warehouse_id) as cnt'])->groupBy(['guid'])->indexBy('guid')->asArray()->all();
+
$stocks = [];
$balancesAll = Balances::find()->where(['product_id' => $componentsGuids, 'store_id' => array_keys($marketplaceStores)])->asArray()->all();
+
+
$balance2Dim = [];
$balanceStoreIds = [];
foreach ($balancesAll as $balance) {
$balance2Dim[$balance['store_id']][$balance['product_id']] = $balance['quantity'];
$balanceStoreIds[] = $balance['store_id'];
}
-
+ //var_dump( $balanceStoreIds );
$balanceStoreIds = array_unique($balanceStoreIds);
- //var_dump($balanceStoreIds);
+
foreach ($bouquetComposition as $guid => $products) {
$stockRecords = [];
foreach ($products as $product_id => $count) {
$stocks[$guid] = ['count' => $bouquetCount, 'store' => $store];
}
}
-
+ //var_dump(ArrayHelper::getColumn($productsGuids, 'id'));
// 5. Получение приоритетов
$priorities = MarketplacePriority::find()
->where(['guid' => ArrayHelper::getColumn($productsGuids, 'id')])->indexBy('guid')->asArray()->all();
-
+ //var_dump($priorities);
// 6. Массив для хранения гуидов, которые можно отправить
$availableGuids = [];
}
}
-
+ // var_dump($availableGuids);
$distribution = [];
foreach ($availableGuids as $product) {
$koefRemain = $priority['reminder_koef'];
$totalBouquets = intval($stock['count'] / $koefRemain); // С учетом коэффициента
-// echo "<pre>"; var_dump($availableGuids); var_dump($totalBouquets); var_dump($stock); die;
+ // echo "<pre>"; var_dump($availableGuids); var_dump($totalBouquets); var_dump($stock); die;
if ($totalBouquets >= 2) {
// Равномерное распределение
foreach ($marketplaceStores as $store) {
}
}
}
+ // var_dump($distribution);
return Json::encode($distribution);
}
}
+ public static function getProductsInfoForFeed(int $warehouseGuid, $storeData)
+ {
+
+
+ if (is_string($storeData)) {
+ $storeData = json_decode($storeData, true);
+
+
+ if (json_last_error() !== JSON_ERROR_NONE) {
+ Yii::error('Невалидный JSON в storeData: ' . json_last_error_msg(), __METHOD__);
+ return [];
+ }
+ }
+
+
+ if (!is_array($storeData)) {
+ Yii::error('Invalid data format for storeData; expected array.', __METHOD__);
+ return [];
+ }
+
+ $store = MarketplaceStore::findOne(['warehouse_guid' => $warehouseGuid]);
+ if (!$store) {
+ Yii::error("Не найден склад для GUID {$warehouseGuid}", __METHOD__);
+ return [];
+ }
+ $storeGuid = $store->guid;
+
+
+ if (!isset($storeData[$storeGuid])) {
+ Yii::warning("Не найдено данных store GUID {$storeGuid}", __METHOD__);
+ return [];
+ }
+
+
+ $productQuantities = $storeData[$storeGuid];
+
+
+ $products = Products1c::find()
+ ->where(['id' => array_keys($productQuantities)])
+ ->andWhere(['!=', 'components', ''])
+ ->all();
+
+ $result = [];
+
+ foreach ($products as $product) {
+ $properties = MarketplaceService::getProductPropertiesByGuid($product->id);
+ if (!$properties) {
+ $message = "Товар с GUID {$product->id} не имеет свойств в MatrixErpProperty и был исключен из фида.";
+ Yii::error($message, __METHOD__);
+
+ InfoLogService::setInfoLog(
+ __FILE__,
+ __LINE__,
+ $message,
+ 'Missing properties error'
+ );
+ continue;
+ }
+
+ $price = MarketplaceService::getProductPrice($product->id);
+
+ /* if ($price == 0) {
+ $message = "У товара {$product->id} отсутствует цена и он будет исключен из фида.";
+ Yii::error($message, __METHOD__);
+
+
+ InfoLogService::setInfoLog(
+ __FILE__,
+ __LINE__,
+ $message,
+ 'Zero price error'
+ );
+ continue;
+ }*/
+
+ $components = json_decode($product->components, true);
+ $composition = [];
+
+ foreach ($components as $componentId => $quantity) {
+ $component = Products1c::findOne(['id' => $componentId]);
+ if ($component && $quantity > 0) {
+ $composition[] = [
+ 'name' => $component->name,
+ 'quantity' => $quantity,
+ 'unit' => 'шт'
+ ];
+ }
+ }
+
+
+ $availableQty = $productQuantities[$product->id] ?? 0;
+
+ $result[] = [
+ 'id' => $product->id,
+ 'name' => $properties['displayName'],
+ 'pictures' => [$properties['imageUrl']],
+ 'price' => $price,
+ 'oldprice' => MarketplaceService::getProductOldPrice($product->id),
+ 'description' => MarketplaceService::getProductDescription($product->id),
+ 'qty' => $availableQty,
+ 'amount' => $availableQty,
+ 'weight' => MarketplaceService::getProductWeight($product->id),
+ 'minorder' => MarketplaceService::getProductMinOrder($product->id),
+ 'composition' => $composition,
+ 'available' => MarketplaceService::getProductAvailability($product->id),
+ 'category_id' => MarketplaceService::getProductCategory($product->id),
+ 'category_name' => $properties['flowwowSubcategory'],
+ 'params' => MarketplaceService::getProductParams($product->id),
+ 'productLink' => MarketplaceService::getProductLinkByGuid($product->id),
+ ];
+ }
+
+ return $result;
+ }
+
/**
* Статический метод для создания XML-фида на основе информации о продуктах.
*
// Добавление веса и количества
$offer->addChild('weight', $product['weight']);
- // $offer->addChild('qty', $product['qty']);
+ $offer->addChild('qty', $product['qty']);
+
// $offer->addChild('amount', $product['amount']);
// $offer->addChild('cost', $product['amount']);