Example #1
0
 /**
  *
  * 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;
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
    ?>
>
	</td>
</tr>

<?php 
    if ($saleIsInstalled && Loader::includeModule('sale')) {
        ?>
	<tr>
		<td id="td_reservation_type"><?php 
        echo Loc::getMessage($strUseStoreControl == 'Y' || $strEnableReservation == 'Y' ? 'CAT_PRODUCT_RESERVED' : 'CAT_PRODUCT_QUANTITY_DECREASE');
        ?>
</td>
		<td>
			<?php 
        $currentReserveCondition = Sale\Configuration::getProductReservationCondition();
        $reserveConditions = Sale\Configuration::getReservationConditionList(true);
        if (isset($reserveConditions[$currentReserveCondition])) {
            echo htmlspecialcharsex($reserveConditions[$currentReserveCondition]);
        } else {
            echo Loc::getMessage('BX_CAT_RESERVE_CONDITION_EMPTY');
        }
        unset($reserveConditions, $currentReserveCondition);
        ?>
&nbsp;<a href="<?php 
        echo $saleSettingsUrl;
        ?>
#section_reservation"><?php 
        echo Loc::getMessage('CAT_DISCOUNT_PERCENT_FROM_BASE_SALE');
        ?>
</a>
Example #4
0
 /**
  * @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();
 }
Example #5
0
 /**
  * @param ShipmentItem $shipmentItem
  * @return Result
  * @throws NotSupportedException
  */
 public static function tryReserveShipmentItem(ShipmentItem $shipmentItem)
 {
     $result = new Result();
     if (floatval($shipmentItem->getQuantity()) == floatval($shipmentItem->getReservedQuantity())) {
         return $result;
     }
     /** @var ShipmentItemCollection $shipmentItemCollection */
     $shipmentItemCollection = $shipmentItem->getCollection();
     $shipment = $shipmentItemCollection->getShipment();
     /** @var ShipmentCollection $shipmentCollection */
     $shipmentCollection = $shipment->getCollection();
     $order = $shipmentCollection->getOrder();
     /** @var BasketItem $basketItem */
     $basketItem = $shipmentItem->getBasketItem();
     if ($basketItem->isBundleParent()) {
         return $result;
     }
     $needQuantity = $shipmentItem->getQuantity() - $shipmentItem->getReservedQuantity();
     $canReserve = false;
     /** @var Result $r */
     $r = static::tryReserveBasketItem($shipmentItem->getBasketItem(), $needQuantity);
     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_RESERVE_SHIPMENT_ITEM_WRONG_AVAILABLE_QUANTITY'), 'PROVIDER_RESERVE_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 ($needQuantity > 0 && $needQuantity > $availableQuantity) {
             //			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;
         }
         // is not completely correct, but will be processed in real reservations while saving
         if ($availableQuantity < 0 && $shipmentItem->getReservedQuantity() + $availableQuantity < 0) {
             $availableQuantity = -1 * $shipmentItem->getReservedQuantity();
         }
         if (Configuration::getProductReservationCondition() != Configuration::RESERVE_ON_SHIP) {
             static::addReservationPoolItem($order->getInternalId(), $shipmentItem->getBasketItem(), $availableQuantity >= $needQuantity ? $needQuantity : $availableQuantity);
             if (Configuration::isEnabledReservation()) {
                 $shipmentItem->setField('RESERVED_QUANTITY', $shipmentItem->getReservedQuantity() + ($availableQuantity >= $needQuantity ? $needQuantity : $availableQuantity));
             }
         }
     }
     $result->addData(array('CAN_RESERVE' => $canReserve));
     return $result;
 }