174 $basketItemsStoreQuantity = [];
175 $currentStoreProductQuantity = $this->storeProductQuantity;
176 $preparedReservationHistory = $this->getPreparedReservationHistory();
178 foreach ($preparedReservationHistory as $item)
180 $storeId = $item[
'storeId'];
181 $productId = $item[
'productId'];
182 $basketId = $item[
'basketId'];
184 $reservationQuantity = $item[
'quantity'];
185 $storeQuantity = $currentStoreProductQuantity[$storeId][$productId] ?? 0.0;
187 $isNeedBasketReservation = isset($basket2productId[$basketId]);
188 if ($isNeedBasketReservation)
190 if ($storeQuantity > 0)
192 $basketItemsStoreQuantity[$basketId][$storeId] ??= 0.0;
193 $basketItemsStoreQuantity[$basketId][$storeId] += min($storeQuantity, $reservationQuantity);
197 if (isset($currentStoreProductQuantity[$storeId][$productId]))
199 $currentStoreProductQuantity[$storeId][$productId] -= $reservationQuantity;
203 foreach ($basket2productId as $basketId => $productId)
205 foreach ($currentStoreProductQuantity as $storeId => $quantities)
208 isset($basketItemsStoreQuantity[$basketId])
209 && !isset($basketItemsStoreQuantity[$basketId][$storeId])
214 $storeQuantity = $quantities[$productId] ?? 0.0;
215 if ($storeQuantity > 0.0)
217 $basketItemsStoreQuantity[$basketId][$storeId] ??= 0.0;
218 $basketItemsStoreQuantity[$basketId][$storeId] += $storeQuantity;
223 return $basketItemsStoreQuantity;