/** * @throws Main\ArgumentOutOfRangeException * @throws Main\NotSupportedException * @throws \Exception */ public function tryReserve() { return Provider::tryReserveShipmentItem($this); }
/** * @internal * * @param BasketItem $basketItem * @param $value * @param $oldValue * * @return Result */ public function syncQuantityAfterModify(BasketItem $basketItem, $value = null, $oldValue = null) { $result = new Result(); $shipmentItemCollection = $this->getShipmentItemCollection(); $shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode()); if ($shipmentItem === null) { if ($value == 0) { return new Result(); } $shipmentItem = $shipmentItemCollection->createItem($basketItem); } $deltaQuantity = $value - $oldValue; if ($deltaQuantity > 0) { $shipmentItem->setFieldNoDemand("QUANTITY", $shipmentItem->getField("QUANTITY") + $deltaQuantity); if ($this->needReservation()) { Provider::tryReserveShipmentItem($shipmentItem); } } else { if (floatval($shipmentItem->getField("QUANTITY")) <= 0) { return new Result(); } if ($value != 0 && $shipmentItem->getField("QUANTITY") < -$deltaQuantity) { $result = new Result(); $result->addError(new ResultError(str_replace(array("#NAME#", "#QUANTITY#", "#DELTA_QUANTITY#"), array($basketItem->getField("NAME"), $shipmentItem->getField("QUANTITY"), abs($deltaQuantity)), Loc::getMessage('SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR')), 'SALE_SHIPMENT_SYSTEM_QUANTITY_ERROR')); return $result; } if ($value > 0) { $shipmentItem->setFieldNoDemand("QUANTITY", $shipmentItem->getField("QUANTITY") + $deltaQuantity); if ($this->needReservation()) { Provider::tryReserveShipmentItem($shipmentItem); } } else { $shipmentItem->setFieldNoDemand("QUANTITY", 0); } } return $result; }
/** * @param $action * @param BasketItem $basketItem * @param null $name * @param null $oldValue * @param null $value */ public function onBasketModify($action, BasketItem $basketItem, $name = null, $oldValue = null, $value = null) { switch ($action) { case "UPDATE": if ($name == "QUANTITY") { /** @var ShipmentItemCollection $collection */ $collection = $this->getCollection(); $shipment = $collection->getShipment(); if ($shipment->isShipped() != "Y") { return true; } if ($basketItem->getBasketCode() != $this->getBasketCode()) { return true; } $quantity = $value - $oldValue; if ($quantity != 0) { $result = Provider::tryReserveShipmentItem($this); } if (!empty($result) && is_array($result)) { $this->setField('RESERVED_QUANTITY', $result['QUANTITY']); if ($quantity > 0) { if ($this->getQuantity() != $this->getReservedQuantity()) { /** @var ShipmentItemCollection $shipmentItemCollection */ $shipmentItemCollection = $this->getCollection(); /** @var Shipment $shipment */ $shipment = $shipmentItemCollection->getShipment(); $shipment->setMark(); } } } } //change quantity break; case "DELETE": // unreserve break; } }