35 $this->saleOptions = array(
36 'APPLY_MODE' => $this::APPLY_MODE_ADD,
58 $instanceIndex = static::getInstanceIndexByFuser((
int)$fuser, (
string)$site);
59 if (!static::instanceExists($instanceIndex))
61 return static::getInstance($instanceIndex);
72 return Registry::REGISTRY_TYPE_ORDER;
93 return $this->shipmentIds;
104 public function createClone(\SplObjectStorage $cloneEntity)
107 $discountClone = parent::createClone($cloneEntity);
109 if ($this->isShipmentExists())
111 if ($cloneEntity->contains($this->shipment))
112 $discountClone->shipment = $cloneEntity[$this->shipment];
115 return $discountClone;
130 if (!empty($this->applyResult[
'DISCOUNT_LIST']))
132 if (!empty($this->applyResult[
'DELIVERY']) && is_array($this->applyResult[
'DELIVERY']))
134 foreach ($this->applyResult[
'DELIVERY'] as $orderDiscountId => $apply)
137 $this->applyResult[
'DISCOUNT_LIST'][$orderDiscountId] =
'Y';
139 unset($apply, $orderDiscountId);
153 return Compatible\DiscountCompatibility::getApplyResult($extMode);
155 $extMode = ($extMode ===
true);
157 $result = parent::getApplyResult($extMode);
160 $result[
'CONVERTED_ORDER'] = (!$this->
isValidState() ?
'Y' :
'N');
165 if (isset($this->discountResult[
'APPLY_BLOCKS'][0][
'BASKET']))
166 $result[
'BASKET'] = $this->discountResult[
'APPLY_BLOCKS'][0][
'BASKET'];
167 if (isset($this->discountResult[
'APPLY_BLOCKS'][0][
'ORDER']))
168 $result[
'ORDER'] = $this->discountResult[
'APPLY_BLOCKS'][0][
'ORDER'];
180 $result = parent::getShowPrices();
197 if ($this->isUsedDiscountCompatibility())
201 $compatibleResult = Compatible\DiscountCompatibility::getResult();
202 if ($compatibleResult ===
false)
204 if (empty($compatibleResult))
207 $this->
setUseMode($compatibleResult[
'CALCULATE'][
'USE_MODE']);
208 $this->newOrder = $compatibleResult[
'CALCULATE'][
'NEW_ORDER'];
209 $this->discountsCache = $compatibleResult[
'DISCOUNT_LIST'];
210 $this->couponsCache = $compatibleResult[
'COUPONS_LIST'];
211 $this->discountResult = $compatibleResult[
'DISCOUNT_RESULT'];
212 $this->forwardBasketTable = $compatibleResult[
'FORWARD_BASKET_TABLE'];
213 $this->reverseBasketTable = $compatibleResult[
'REVERSE_BASKET_TABLE'];
216 $shipmentResult = $this->loadShipment();
217 if (!$shipmentResult->isSuccess())
219 $result->addErrors($shipmentResult->getErrors());
220 unset($shipmentResult);
223 unset($shipmentResult);
226 unset($compatibleResult);
229 $result = parent::save();
242 $config = parent::getOrderConfig();
243 $config[
'DELIVERY'] = [
244 'DELIVERY_ID' => $this->orderData[
'DELIVERY_ID'],
245 'CUSTOM_PRICE_DELIVERY' => $this->orderData[
'CUSTOM_PRICE_DELIVERY'],
248 if ($this->shipment instanceof $shipmentClassName)
249 $config[
'DELIVERY'][
'SHIPMENT_ID'] = $this->shipment->getId();
250 unset($shipmentClassName);
266 return '0|'.$fuser.
'|'.$site;
279 return parent::getExecuteFieldList();
280 return [
'PREDICTIONS_APP',
'APPLICATION'];
293 return parent::getConditionField();
294 return 'PREDICTIONS_APP';
305 $result = parent::getStepResult($order);;
306 $stepResult = &$order[
'DISCOUNT_RESULT'];
307 if (!empty($stepResult[
'DELIVERY']) && is_array($stepResult[
'DELIVERY']))
309 $result[
'DELIVERY'] = array(
311 'DELIVERY_ID' => (isset($order[
'DELIVERY_ID']) ? $order[
'DELIVERY_ID'] :
false),
312 'SHIPMENT_CODE' => (isset($order[
'SHIPMENT_CODE']) ? $order[
'SHIPMENT_CODE'] :
false),
314 'DESCR_DATA' => $stepResult[
'DELIVERY'],
315 'ACTION_BLOCK_LIST' => array_keys($stepResult[
'DELIVERY'])
317 if (is_array($result[
'DELIVERY'][
'DESCR']))
318 $result[
'DELIVERY'][
'DESCR'] = implode(
', ', $result[
'DELIVERY'][
'DESCR']);
333 parent::normalizeDiscountResult();
335 if (empty($this->orderData))
340 $customPrice = isset($this->orderData[
'CUSTOM_PRICE_DELIVERY']) && $this->orderData[
'CUSTOM_PRICE_DELIVERY'] ==
'Y';
341 $this->orderData[
'PRICE_DELIVERY_DIFF'] = (!$customPrice
342 ? PriceMaths::roundPrecision($this->orderData[
'PRICE_DELIVERY_DIFF'])
347 if ($this->orderData[
'PRICE_DELIVERY_DIFF'] > 0)
348 $this->orderData[
'PRICE_DELIVERY'] = $this->orderData[
'BASE_PRICE_DELIVERY'] - $this->orderData[
'PRICE_DELIVERY_DIFF'];
350 $this->orderData[
'PRICE_DELIVERY'] = PriceMaths::roundPrecision($this->orderData[
'PRICE_DELIVERY']);
362 parent::getApplyPrices();
373 parent::remakingDiscountResult();
376 if (!empty($this->discountResult[
'APPLY_BLOCKS']))
378 foreach ($this->discountResult[
'APPLY_BLOCKS'] as $counter => $applyBlock)
380 if (!empty($applyBlock[
'ORDER']))
382 foreach ($applyBlock[
'ORDER'] as $discount)
384 if (!empty($discount[
'RESULT'][
'DELIVERY']))
387 'DISCOUNT_ID' => $discount[
'DISCOUNT_ID'],
388 'COUPON_ID' => $discount[
'COUPON_ID'],
389 'DELIVERY_ID' => $discount[
'RESULT'][
'DELIVERY'][
'DELIVERY_ID'],
390 'APPLY' => $discount[
'RESULT'][
'DELIVERY'][
'APPLY'],
391 'DESCR' => $discount[
'RESULT'][
'DELIVERY'][
'DESCR']
398 unset($counter, $applyBlock);
400 $this->discountResult[
'RESULT'][
'DELIVERY'] = $delivery;
412 'BASE_PRICE' => $this->orderData[
'BASE_PRICE_DELIVERY'] ?? 0.0,
413 'PRICE' => $this->orderData[
'PRICE_DELIVERY'] ?? 0.0,
414 'DISCOUNT' => $this->orderData[
'PRICE_DELIVERY_DIFF'] ?? 0.0,
428 if (!empty($this->discountResult[
'APPLY_BLOCKS']))
430 foreach ($this->discountResult[
'APPLY_BLOCKS'] as $counter => $applyBlock)
432 if (!empty($applyBlock[
'ORDER']))
434 foreach ($applyBlock[
'ORDER'] as $discount)
436 if (empty($discount[
'RESULT'][
'DELIVERY']))
438 $id = $discount[
'RESULT'][
'DELIVERY'][
'DELIVERY_ID'];
439 $delivery[$id] = $id;
441 unset($id, $discount);
444 unset($counter, $applyBlock);
446 $result[
'DELIVERY_LIST'] = (empty($delivery) ? array() : array_values($delivery));
451 if ($this->shipment instanceof $shipmentClassName)
452 $shipment[] = $this->shipment->getShipmentCode();
466 parent::fillEmptyDiscountResult();
467 $this->discountResult[
'DELIVERY_LIST'] = [];
468 $this->discountResult[
'SHIPMENT_LIST'] = [];
478 $result = parent::fillDiscountResult();
480 $orderKeys = [
'PRICE_DELIVERY',
'PRICE_DELIVERY_DIFF'];
481 foreach ($orderKeys as $key)
483 if (isset($this->orderData[$key]))
484 $result[$key] = $this->orderData[$key];
486 unset($key, $orderKeys);
487 if (isset($result[
'PRICE_DELIVERY_DIFF']))
489 $result[
'DISCOUNT_PRICE'] = $result[
'PRICE_DELIVERY_DIFF'];
490 unset($result[
'PRICE_DELIVERY_DIFF']);
494 $result[
'SHIPMENT'] =
null;
495 if ($this->shipment instanceof $shipmentClassName)
496 $result[
'SHIPMENT'] = $this->shipment->getShipmentCode();
497 unset($shipmentClassName);
509 parent::resetPrices();
520 if ($this->orderData[
'CUSTOM_PRICE_DELIVERY'] !==
'N')
522 $this->orderData[
'PRICE_DELIVERY'] = $this->orderData[
'BASE_PRICE_DELIVERY'];
523 $this->orderData[
'PRICE_DELIVERY_DIFF'] = 0;
533 $result = parent::loadOrderData();
534 if (!$result->isSuccess())
539 $this->shipmentIds = [];
540 $shipmentResult = $this->loadShipment();
541 if (!$shipmentResult->isSuccess())
543 $result->addErrors($shipmentResult->getErrors());
546 unset($shipmentResult);
558 protected function fillEmptyOrderData()
560 parent::fillEmptyOrderData();
561 $this->orderData += [
562 'BASE_PRICE_DELIVERY' => 0,
563 'PRICE_DELIVERY' => 0,
564 'PRICE_DELIVERY_DIFF' => 0,
566 'CUSTOM_PRICE_DELIVERY' =>
'N',
567 'SHIPMENT_CODE' => 0,
572 if ($this->isOrderExists())
575 $order = $this->getOrder();
577 $this->orderData[
'PAY_SYSTEM_ID'] =
null;
578 $paymentCollection = $order->getPaymentCollection();
580 foreach ($paymentCollection as $payment)
582 if ($payment->isInner())
584 if (!isset($this->orderData[
'PAY_SYSTEM_ID']))
586 $this->orderData[
'PAY_SYSTEM_ID'] = (int)$payment->getPaymentSystemId();
590 unset($payment, $paymentCollection);
591 if (!isset($this->orderData[
'PAY_SYSTEM_ID']))
592 $this->orderData[
'PAY_SYSTEM_ID'] = 0;
604 protected function loadBasket()
606 $result = parent::loadBasket();
607 if (!$result->isSuccess())
615 foreach ($basket as $basketItem)
618 !$basketItem->canBuy()
619 || !$basketItem->isBundleParent()
623 $bundle = $basketItem->getBundleCollection();
624 if ($bundle->count() == 0)
626 $result->addError(
new Main\Entity\EntityError(
633 foreach ($bundle as $bundleItem)
636 $item[
'IN_SET'] =
'Y';
637 $this->orderData[
'BASKET_ITEMS'][$bundleItem->getBasketCode()] = $item;
639 unset($item, $bundle, $bundleItem);
654 parent::loadDefaultOrderConfig();
656 $this->shipment =
null;
665 protected function applyLoadedOrderConfig(array $data)
667 parent::applyLoadedOrderConfig($data);
669 if (isset($data[
'OLD_ORDER']))
670 $this->setValidState(
false);
673 $order = $this->getOrder();
674 if (!empty($data[
'DELIVERY']))
676 $delivery = $data[
'DELIVERY'];
677 $this->orderData[
'DELIVERY_ID'] = $delivery[
'DELIVERY_ID'];
678 if (isset($delivery[
'CUSTOM_PRICE_DELIVERY']))
679 $this->orderData[
'CUSTOM_PRICE_DELIVERY'] = $delivery[
'CUSTOM_PRICE_DELIVERY'];
680 if (isset($delivery[
'SHIPMENT_ID']))
682 $delivery[
'SHIPMENT_ID'] = (int)$delivery[
'SHIPMENT_ID'];
683 if ($delivery[
'SHIPMENT_ID'] > 0)
685 $this->shipmentIds[] = $delivery[
'SHIPMENT_ID'];
687 $orderShipmentList = $order->getShipmentCollection();
688 $this->shipment = $orderShipmentList->getItemById($delivery[
'SHIPMENT_ID']);
689 if (empty($this->shipment))
691 $this->shipment =
null;
692 $this->shipmentIds = array();
710 return ($this->shipment instanceof $shipmentClassName);
723 $this->orderData[
'DELIVERY_ID'] = $this->shipment->getDeliveryId();
724 $this->orderData[
'CUSTOM_PRICE_DELIVERY'] = ($this->shipment->isCustomPrice() ?
'Y' :
'N');
725 $this->orderData[
'BASE_PRICE_DELIVERY'] = $this->shipment->getField(
'BASE_PRICE_DELIVERY');
726 $this->orderData[
'PRICE_DELIVERY'] = $this->shipment->getPrice();
727 $this->orderData[
'PRICE_DELIVERY_DIFF'] = $this->shipment->getField(
'DISCOUNT_PRICE');
728 $this->orderData[
'SHIPMENT_CODE'] = $this->shipment->getShipmentCode();
729 $this->orderData[
'SHIPMENT_ID'] = (int)$this->shipment->getId();
737 protected function loadShipment()
740 if (!$this->isOrderExists())
742 if (!$this->isShipmentExists())
744 $loadDelivery =
false;
746 $order = $this->getOrder();
748 $orderShipmentList = $order->getShipmentCollection();
750 if ($this->isOrderNew())
752 foreach ($orderShipmentList as $shipment)
754 if ($shipment->isSystem())
759 $this->shipment = $shipment;
760 $loadDelivery =
true;
768 foreach ($orderShipmentList as $shipment)
770 if ($shipment->isSystem())
773 $currentShipmentId = (int)$shipment->getId();
774 if ($shipmentId ===
false || $shipmentId > $currentShipmentId)
775 $shipmentId = $currentShipmentId;
777 unset($currentShipmentId, $shipment);
778 if (!empty($shipmentId))
780 $this->shipment = $orderShipmentList->getItemById($shipmentId);
781 $loadDelivery =
true;
785 unset($loadDelivery);
797 parent::initInstanceFromOrder();
798 $this->loadShipment();
814 switch ($entity[
'ENTITY_TYPE'])
816 case self::ENTITY_DELIVERY:
818 'ENTITY_TYPE' => self::ENTITY_DELIVERY,
819 'ENTITY_ID' => (int)$entity[
'ENTITY_CODE'],
820 'ENTITY_VALUE' => (
string)$entity[
'ENTITY_CODE']
824 $result = parent::getEntitySaveIdentifier($entity);
839 private function isUsedDiscountCompatibility()
851 $this->orderData[
'USE_BASE_PRICE'] = $this->saleOptions[
'USE_BASE_PRICE'];
887 return (isset($this->orderData[$code]) ? $this->orderData[$code][
'BASE_PRICE'] :
null);
930 $order = $basket->getOrder();
932 return static::buildFromOrder(
$order);
934 return self::buildFromBasket($basket,
new Context\
Fuser($basket->getFUserId(
true)));
948 return static::buildFromOrder($order);
959 public function saveExternalLastApplyblock(
BasketItem $basketItem, $orderDiscountId)
963 $this->order = $basket->getOrder();
965 $this->loadOrderData();
967 $listItems[$basketItem->
getBasketCode()] = array(
'APPLY'=>
'Y',
'ACTION_BLOCK_LIST'=>array(),
'DESCR_DATA'=>array(),
'DESCR'=>array());
969 $this->discountsCache[$orderDiscountId][
'MODULE_ID'] =
'sale';
970 $applyBlock = &$this->discountResult[
'APPLY_BLOCKS'][$this->discountResultCounter];
971 $applyBlock[
'ORDER'][] = array(
972 'DISCOUNT_ID' => $orderDiscountId,
974 'RESULT' => array(
'BASKET' => $listItems)
977 $this->saveLastApplyBlock();
989 return $this->getCurrency();
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)