/** * * Deletes all shipments and creates system shipment containing the whole basket * * @internal * * @return Result * @throws Main\NotSupportedException * @throws Main\ObjectNotFoundException */ public function resetCollection() { /** @var Order $order */ if (!($order = $this->getOrder())) { throw new Main\ObjectNotFoundException('Entity "Order" not found'); } /** @var Basket $basket */ if (!($basket = $order->getBasket())) { throw new Main\ObjectNotFoundException('Entity "Basket" not found'); } $result = new Result(); $deliveryInfo = array(); if (count($this->collection) > 0) { /** @var Shipment $shipment */ foreach ($this->collection as $shipment) { if (empty($deliveryInfo)) { if ($shipment->isSystem() && $shipment->getDeliveryId() > 0) { foreach (static::getClonedFields() as $field) { if (strval(trim($shipment->getField($field))) != '') { $deliveryInfo[$field] = trim($shipment->getField($field)); } } } } $shipment->delete(); } } $systemShipment = $this->getSystemShipment(); $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection(); $systemShipmentItemCollection->resetCollection($basket); if (!empty($deliveryInfo)) { $systemShipment->setFieldsNoDemand($deliveryInfo); } if (Configuration::getProductReservationCondition() == Configuration::RESERVE_ON_CREATE) { /** @var Result $r */ $r = $this->tryReserve(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } return $result; }
/** * @param null $oldPaid * @return Result * @throws Main\ObjectNotFoundException */ protected function onAfterSyncPaid($oldPaid = null) { global $USER; $result = new Result(); /** @var PaymentCollection $paymentCollection */ if (!($paymentCollection = $this->getPaymentCollection())) { throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found'); } /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $this->getShipmentCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } $oldPaidBool = null; if ($oldPaid !== null) { $oldPaidBool = $oldPaid == "Y"; } if ($oldPaid == "N" && $this->isPaid()) { $orderStatus = Config\Option::get('sale', 'status_on_paid', ''); if (strval($orderStatus) != '') { if ($USER && $USER->isAuthorized()) { $statusesList = OrderStatus::getAllowedUserStatuses($USER->getID(), $this->getField('STATUS_ID')); $statusesList = array_keys($statusesList); } else { $statusesList = OrderStatus::getAllStatuses(); } if ($this->getField('STATUS_ID') != $orderStatus && in_array($orderStatus, $statusesList)) { $this->setField('STATUS_ID', $orderStatus); } } } if ($oldPaid !== null && $this->isPaid() != $oldPaidBool) { Internals\EventsPool::addEvent($this, EventActions::EVENT_ON_ORDER_PAID, array('ENTITY' => $this)); Internals\EventsPool::addEvent($this, EventActions::EVENT_ON_ORDER_PAID_SEND_MAIL, array('ENTITY' => $this)); } if (Configuration::getProductReservationCondition() == Configuration::RESERVE_ON_PAY) { if ($paymentCollection->hasPaidPayment()) { $r = $shipmentCollection->tryReserve(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } else { $r = $shipmentCollection->tryUnreserve(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } elseif (Configuration::getProductReservationCondition() == Configuration::RESERVE_ON_FULL_PAY) { if ($oldPaid == "N" && $this->isPaid()) { $r = $shipmentCollection->tryReserve(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } elseif ($oldPaid == "Y" && !$this->isPaid()) { $r = $shipmentCollection->tryUnreserve(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } if (Configuration::needAllowDeliveryOnPay()) { if ($oldPaid == "N" && $this->isPaid()) { $r = $shipmentCollection->allowDelivery(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } elseif ($oldPaid == "Y" && !$this->isPaid()) { $r = $shipmentCollection->disallowDelivery(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } return $result; }
?> </a> </td> </tr> <tr id="tr_reservation_period" style="display: <?php echo $strUseStoreControl == 'Y' || $strEnableReservation == 'Y' ? 'table-row' : 'none'; ?> ;"> <td> <?php echo Loc::getMessage("CAT_RESERVATION_CLEAR_PERIOD"); ?> </td> <td> <?php echo Sale\Configuration::getProductReserveClearPeriod(); ?> </td> </tr> <?php } if (!$useSaleDiscountOnly) { if (CBXFeatures::IsFeatureEnabled('CatDiscountSave')) { ?> <tr class="heading"> <td colspan="2"><?php echo Loc::getMessage("CAT_DISCOUNT"); ?> </td> </tr> <tr>
/** * @internal * * @return bool */ public function needReservation() { $condition = Configuration::getProductReservationCondition(); if ($condition == Configuration::RESERVE_ON_CREATE) { return true; } if ($condition == Configuration::RESERVE_ON_PAY || $condition == Configuration::RESERVE_ON_FULL_PAY) { /** @var ShipmentCollection $collection */ $collection = $this->getCollection(); $order = $collection->getOrder(); if ($condition == Configuration::RESERVE_ON_FULL_PAY) { return $order->isPaid(); } $paymentCollection = $order->getPaymentCollection(); return $paymentCollection->hasPaidPayment(); } if ($this->isSystem()) { return false; } return $condition == Configuration::RESERVE_ON_ALLOW_DELIVERY && $this->isAllowDelivery() || $condition == Configuration::RESERVE_ON_SHIP && $this->isShipped(); }
</tr> <!-- end of ps success and fail paths --> <tr class="heading"> <td colspan="2"><a name="section_reservation"></a><?php echo GetMessage('BX_SALE_SETTINGS_SECTION_RESERVATION'); ?> </td> </tr> <tr> <td width="40%"><?php echo GetMessage('BX_SALE_SETTINGS_OPTION_PRODUCT_RESERVE_CONDITION'); ?> </td> <td width="60%"><select name="product_reserve_condition"> <?php foreach (Sale\Configuration::getReservationConditionList(true) as $reserveId => $reserveTitle) { ?> <option value="<?php echo $reserveId; ?> "<?php echo $reserveId == $currentSettings['product_reserve_condition'] ? ' selected' : ''; ?> ><?php echo htmlspecialcharsex($reserveTitle); ?> </option> <?php } unset($reserveId, $reserveTitle); ?>
/** * @param ShipmentItem $shipmentItem * @return float|int|null * @throws NotSupportedException * @throws SystemException */ public static function tryUnreserveShipmentItem(ShipmentItem $shipmentItem) { if (Configuration::isEnabledReservation() && $shipmentItem->getReservedQuantity() == 0) { return new Result(); } $result = new Result(); /** @var BasketItem $basketItem */ $basketItem = $shipmentItem->getBasketItem(); if ($basketItem->isBundleParent()) { return $result; } /** @var ShipmentItemCollection $shipmentItemCollection */ $shipmentItemCollection = $shipmentItem->getCollection(); $shipment = $shipmentItemCollection->getShipment(); /** @var ShipmentCollection $shipmentCollection */ $shipmentCollection = $shipment->getCollection(); $order = $shipmentCollection->getOrder(); if (Configuration::isEnabledReservation()) { $quantity = $shipmentItem->getReservedQuantity(); } else { $quantity = $shipmentItem->getQuantity(); } $canReserve = false; /** @var Result $r */ $r = static::tryReserveBasketItem($shipmentItem->getBasketItem(), -1 * $quantity); if ($r->isSuccess()) { $availableQuantityData = $r->getData(); if (array_key_exists('AVAILABLE_QUANTITY', $availableQuantityData)) { $availableQuantity = $availableQuantityData['AVAILABLE_QUANTITY']; } else { $result->addError(new ResultError(Loc::getMessage('PROVIDER_UNRESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY'), 'PROVIDER_UNRESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY')); return $result; } if (array_key_exists('HAS_PROVIDER', $availableQuantityData)) { $canReserve = $availableQuantityData['HAS_PROVIDER']; } if ($canReserve && array_key_exists('QUANTITY_TRACE', $availableQuantityData)) { $canReserve = $availableQuantityData['QUANTITY_TRACE']; } } else { $result->addErrors($r->getErrors()); return $result; } if ($canReserve) { if ($availableQuantity > 0) { // throw new SystemException("availableQuantity"); $result->addError(new ResultError(Loc::getMessage("SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_QUANTITY_NOT_ENOUGH"), "SALE_PROVIDER_RESERVE_SHIPMENT_ITEM_QUANTITY_NOT_ENOUGH")); return $result; } static::addReservationPoolItem($order->getInternalId(), $shipmentItem->getBasketItem(), $availableQuantity); if (Configuration::isEnabledReservation()) { $shipmentItem->setField('RESERVED_QUANTITY', $shipmentItem->getReservedQuantity() + $availableQuantity); } } $result->addData(array('CAN_RESERVE' => $canReserve)); return $result; }