319 $result =
new Sale\Result();
322 if (!$shipmentCollection = $shipment->getCollection())
324 throw new Main\ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
328 $order = $shipmentCollection->getOrder();
331 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
334 $context = static::prepareContext($order, $context);
335 $r = static::checkContext($context);
336 if (!$r->isSuccess())
344 $shipmentItemCollection = $shipment->getShipmentItemCollection();
346 $availableQuantityList = array();
347 $needQuantityList = array();
350 $r = static::getNeedQuantityByShipmentItemCollection($shipmentItemCollection);
351 if (!$r->isSuccess())
353 $result->addErrors($r->getErrors());
357 $data = $r->getData();
358 if (!empty($data[
'NEED_QUANTITY_LIST']))
360 $needQuantityList = $data[
'NEED_QUANTITY_LIST'];
364 if ($r->hasWarnings())
366 $result->addWarnings($r->getWarnings());
369 if ($shipmentItemCollection->count() == 0)
376 foreach ($shipmentItemCollection as $shipmentItem)
378 $shipmentProductData = $creator->createItemForReserve($shipmentItem);
379 $creator->addShipmentProductData($shipmentProductData);
382 $r = $creator->getAvailableQuantity();
385 $data = $r->getData();
386 if (array_key_exists(
'AVAILABLE_QUANTITY_LIST', $data))
388 $availableQuantityList = $data[
'AVAILABLE_QUANTITY_LIST'] + $availableQuantityList;
393 $result->addErrors($r->getErrors());
396 if ($r->hasWarnings())
398 $result->addWarnings($r->getWarnings());
401 if (!empty($needQuantityList) && $result->isSuccess())
403 $applyItemsList = array();
405 foreach ($availableQuantityList as $providerName => $productAvailableQuantityList)
407 $providerName = trim($providerName);
408 foreach ($productAvailableQuantityList as $productId => $productAvailableQuantity)
410 if (array_key_exists($productId, $needQuantityList[$providerName]))
415 if ($order->getId() > 0)
419 $needQuantity = $needQuantityList[$providerName][$productId];
421 $productAvailableQuantity -= $poolQuantity;
422 $reservedQuantity = ($needQuantity >= $productAvailableQuantity ? $productAvailableQuantity : $needQuantity);
424 $applyItemsList[$providerName][$productId] = $reservedQuantity;
430 foreach ($shipmentItemCollection as $shipmentItem)
432 $basketItem = $shipmentItem->getBasketItem();
434 if ($basketItem->getProductId() == $productId)
436 $result->addWarning(
new Sale\ResultWarning(Main\Localization\
Loc::getMessage(
'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY', array(
437 '#PRODUCT_NAME#' => $basketItem->getField(
'NAME')
438 )),
'SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY') );
447 if (!empty($applyItemsList))
449 $shipmentProductIndex = static::createProductShipmentItemMapByShipmentItemCollection($shipmentItemCollection);
452 if (!$shipment = $shipmentItemCollection->getShipment())
454 throw new Main\ObjectNotFoundException(
'Entity "ShipmentItemCollectionCollection" not found');
458 if (!$shipmentCollection = $shipment->getCollection())
460 throw new Main\ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
464 if (!$order = $shipmentCollection->getOrder())
466 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
471 static::setAvailableQuantityToShipmentItemCollection($pool, $shipmentProductIndex, $applyItemsList);
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
static getProductReservationCondition()
Returns current reservation condition.