$quantity = $value['quantity'];
$value['title'] = [];
- // Skip if store_id is not in forecast
if (!isset($forecast[$storeId])) {
continue;
}
foreach (['offline', 'marketplace', 'online'] as $channel) {
- // Initialize channel data in title
- $value['title'][$channel] = [];
$channelData = $forecast[$storeId][$channel] ?? [];
+ // Prioritize share if it exists
if (isset($channelData['share']) && is_numeric($channelData['share'])) {
$value['title'][$channel] = round($quantity * $channelData['share'], 2);
+ continue; // Skip product-specific data if share exists
}
+ // Use product-specific forecast if available
if (isset($productData['product_id']) && isset($forecast[$storeId][$productData['product_id']][$channel])) {
$details = $forecast[$storeId][$productData['product_id']][$channel];
$total = array_sum($details);
round($quantity * $total, 2),
'details' => array_map(fn($val) => round($val, 2), $details),
];
+ } else {
+ $value['title'][$channel] = []; // Empty if neither share nor details exist
}
}
}