43 return Sale\Registry::REGISTRY_TYPE_ORDER;
53 return OrderTable::getEntity();
61 return BasketCompatibility::class;
73 $this->query =
new OrderQuery(static::getEntity());
98 $this->basket = $basketCompatibility;
105 public static function create(array
$fields)
107 $adminSection = (defined(
'ADMIN_SECTION') && ADMIN_SECTION ===
true);
109 $orderCompatibility =
new static();
113 $registry = Sale\Registry::getInstance(static::getRegistryType());
115 $orderClassName = $registry->getOrderClassName();
127 $userId =
$fields[
'USER_ID'] ??
null;
128 $currency =
$fields[
'CURRENCY'] ??
null;
129 if (!
$order = $orderClassName::create($lid, $userId, $currency))
135 if (isset(
$fields[
'PERSON_TYPE_ID']) && intval(
$fields[
'PERSON_TYPE_ID']) > 0)
140 $orderFields = static::replaceFields(
$fields, static::getOrderReplaceFields());
142 $orderFields = $orderCompatibility->parseRawFields(static::ENTITY_ORDER, $orderFields);
144 $orderFields = static::clearFields($orderFields);
145 foreach (static::getFieldsFromOtherEntities() as $wrongField)
147 if (array_key_exists($wrongField,
$fields))
148 unset($orderFields[$wrongField]);
151 $orderFields = static::convertDateFields($orderFields, static::getOrderDateFields());
153 unset($orderFields[
'MARKED']);
154 unset($orderFields[
'CANCELED']);
156 if (array_key_exists(
'PRICE', $orderFields))
158 $orderCompatibility->externalPrice = $orderFields[
'PRICE'];
165 unset($orderFields[
'PRICE']);
168 unset($orderFields[
'PRICE_DELIVERY']);
169 unset($orderFields[
'DISCOUNT_VALUE']);
170 unset($orderFields[
'TAX_VALUE']);
171 $order->setField(
'DATE_UPDATE',
new Main\
Type\DateTime());
176 unset($orderFields[
'SUM_PAID']);
178 $order->setField(
'DATE_INSERT',
new Main\
Type\DateTime());
179 $order->setField(
'DATE_UPDATE',
new Main\
Type\DateTime());
182 unset($orderFields[
'TAX_PRICE']);
184 if (array_key_exists(
'STATUS_ID', $orderFields) &&
$order->getId() > 0)
186 $order->setField(
'STATUS_ID', $orderFields[
'STATUS_ID']);
187 unset($orderFields[
'STATUS_ID']);
190 if (isset($orderFields[
'USE_VAT']) && $orderFields[
'USE_VAT'] ===
true)
192 $orderFields[
'USE_VAT'] =
'Y';
195 $order->setFieldsNoDemand($orderFields);
197 $orderCompatibility->order =
$order;
199 $orderCompatibility->requestFields =
$fields;
203 return $orderCompatibility;
219 $result =
new Sale\Result();
220 if (isset(
$fields[
'CANCELED']))
224 if (!(\CSaleOrder::CanUserCancelOrder(
$order->getId(), $USER->GetUserGroupArray(), $USER->GetID())))
226 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_CANCEL_NO_PERMISSION'),
'SALE_COMPATIBLE_ORDER_CANCEL_NO_PERMISSION') );
232 if (!$r->isSuccess())
234 $result->addErrors($r->getErrors());
238 if (array_key_exists(
"REASON_CANCELED",
$fields))
241 $r =
$order->setField(
'REASON_CANCELED',
$fields[
'REASON_CANCELED']);
242 if (!$r->isSuccess())
244 $result->addErrors($r->getErrors());
260 if (!empty(
$fields[
'REASON_MARKED']))
262 $reasonMarked = trim(
$fields[
'REASON_MARKED']);
265 $r =
new Sale\Result();
266 $r->addError(
new Sale\ResultWarning($reasonMarked,
'SALE_ORDER_MARKER_ERROR'));
268 $registry = Sale\Registry::getInstance(static::getRegistryType());
271 $entityMarkerClassName = $registry->getEntityMarkerClassName();
279 if (!$r->isSuccess())
281 $result->addErrors($r->getErrors());
291 '=ACCOUNT_NUMBER' =>
$fields[
'ACCOUNT_NUMBER'],
294 'select' => array(
'ID')
297 $registry = Sale\Registry::getInstance(static::getRegistryType());
300 $orderClassName = $registry->getOrderClassName();
301 if (($res = $orderClassName::getList(
$filter)) && ($res->fetch()))
303 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_ACCOUNT_NUMBER_ALREADY_EXISTS'),
'SALE_COMPATIBLE_ORDER_ACCOUNT_NUMBER_ALREADY_EXISTS'));
328 public function fillShipmentCollectionFromRequest(
Sale\ShipmentCollection $shipmentCollection, array
$fields)
330 $result =
new Sale\Result();
333 if (!
$order = $shipmentCollection->getOrder())
335 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
340 $deliveryCode = isset(
$fields[
'DELIVERY_ID']) && strval(trim(
$fields[
'DELIVERY_ID'])) !=
'' ? trim(
$fields[
'DELIVERY_ID']) : null;
342 if (strval(trim($deliveryCode)) !=
'')
344 $deliveryId = \CSaleDelivery::getIdByCode($deliveryCode);
351 if (count($shipmentCollection) == 2 && $shipmentCollection->isExistsSystemShipment())
354 foreach($shipmentCollection as $shipment)
356 if ($shipment->isSystem())
359 if ($deliveryId > 0 && $deliveryId != $shipment->getDeliveryId())
362 $r = $shipment->setField(
'DELIVERY_ID', $deliveryId);
366 $deliveryService = Sale\Delivery\Services\Manager::getObjectById($deliveryId);
367 if ($deliveryService)
369 $fields[
'DELIVERY_NAME'] = $deliveryService->isProfile()
370 ? $deliveryService->getNameWithParent()
371 : $deliveryService->getName();
375 $fields[
'DELIVERY_NAME'] =
'Not found [' . $deliveryId .
']';
380 $result->addErrors($r->getErrors());
383 elseif (intval($deliveryId) == 0 && array_key_exists(
'DELIVERY_ID',
$fields) || (intval($deliveryId) !== intval($deliveryCode)))
388 if (array_key_exists(
'PRICE_DELIVERY',
$fields) && (
float)
$fields[
'PRICE_DELIVERY'] != $shipment->getField(
'PRICE_DELIVERY'))
390 $fields[
'BASE_PRICE_DELIVERY'] = (float)
$fields[
'PRICE_DELIVERY'];
391 $fields[
'CUSTOM_PRICE_DELIVERY'] =
"Y";
393 unset(
$fields[
'PRICE_DELIVERY']);
396 $shipmentFields = static::convertDateFields(
$fields, static::getEntityDateFields($shipment));
398 unset($shipmentFields[
'ALLOW_DELIVERY']);
399 unset($shipmentFields[
'DEDUCTED']);
401 if (
$fields[
'CURRENCY'] != $shipmentFields[
'CURRENCY'])
403 $shipmentFields[
'CURRENCY'] =
$fields[
'CURRENCY'];
407 $r = $shipment->setFields(static::clearFields($shipmentFields, static::getShipmentAvailableFields()));
410 static::fillOrderFieldsFromEntity(
$order, $shipment,
$fields, static::getShipmentFieldsToConvert());
414 $result->addErrors($r->getErrors());
417 if ($shipment !==
null)
429 if (intval($deliveryId) == 0)
431 $deliveryId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId();
434 if (intval($deliveryId) > 0)
437 if ($shipment = static::createShipmentFromRequest($shipmentCollection, $deliveryId,
$fields))
439 if (isset(
$fields[
'TRACKING_NUMBER']) && strval(
$fields[
'TRACKING_NUMBER']) !=
'')
441 $shipment->setField(
'TRACKING_NUMBER',
$fields[
'TRACKING_NUMBER']);
444 if (isset(
$fields[
'DELIVERY_EXTRA_SERVICES']) && is_array(
$fields[
'DELIVERY_EXTRA_SERVICES']))
446 $shipment->setExtraServices(
$fields[
'DELIVERY_EXTRA_SERVICES']);
449 if (isset(
$fields[
'STORE_ID']) && intval(
$fields[
'STORE_ID']) > 0)
451 $shipment->setStoreId(
$fields[
'STORE_ID']);
454 if ($shipment !==
null)
459 static::fillOrderFieldsFromEntity(
$order, $shipment,
$fields, static::getShipmentFieldsToConvert());
467 $basketCompatibilityClassName = static::getBasketCompatibilityClassName();
470 $r = $basketCompatibilityClassName::syncShipmentCollectionAndBasket($shipmentCollection,
$basket);
471 if (!$r->isSuccess())
473 $result->addErrors($r->getErrors());
480 $r = static::syncShipmentCollectionFromRequest($shipmentCollection,
$fields);
481 if (!$r->isSuccess())
483 $result->addErrors($r->getErrors());
489 foreach ($shipmentCollection as $shipment)
491 if ($shipment->isSystem())
495 if (!$shipmentItemCollection = $shipment->getShipmentItemCollection())
497 throw new Main\ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
500 if (!empty(
$fields[
'BARCODE_LIST']) && is_array(
$fields[
'BARCODE_LIST']))
503 $r = static::fillShipmentItemCollectionFromRequest($shipmentItemCollection,
$fields[
'BARCODE_LIST'],
$basket);
504 if (!$r->isSuccess())
506 $result->addErrors($r->getErrors());
522 private static function fillOrderFieldsFromEntity(
Sale\Order
$order,
Sale\Internals\CollectableEntity $entity, array
$requestFields, array $allowFields)
524 $dateFields = static::getEntityDateFields($entity);
525 foreach ($allowFields as $checkField)
527 $checkOrderField =
$order->getField($checkField);
531 if (array_key_exists($checkField, $dateFields))
534 $checkOrderField = static::convertDateFieldToOldFormat(
$order->getField($checkField));
539 $setValue = $entity->getField($checkField);
542 $setValue = static::convertDateField($checkField,
$requestFields[$checkField], static::getEntityDateFields($entity));
545 if (in_array($checkField, static::getAvailableFields()))
547 $order->setFieldNoDemand($checkField, $setValue);
565 if (intval($deliveryId) > 0 && $service =
Sale\
Delivery\Services\Manager::getObjectById($deliveryId))
568 $shipment = $shipmentCollection->createItem($service);
570 if ($service->isProfile())
571 $serviceName = $service->getNameWithParent();
573 $serviceName = $service->getName();
574 $shipment->setField(
'DELIVERY_NAME', $serviceName);
584 $basePriceDelivery = $priceDelivery + floatval(
$requestFields[
'PRICE_DELIVERY_DIFF']);
587 $shipment->setFieldNoDemand(
'BASE_PRICE_DELIVERY', $basePriceDelivery);
588 $shipment->setFieldNoDemand(
'CURRENCY',
$requestFields[
'CURRENCY']);
590 $shipment->setFieldNoDemand(
'PRICE_DELIVERY', $priceDelivery);
593 $shipment->setFieldNoDemand(
'PRICE_DELIVERY',
$requestFields[
'PRICE_DELIVERY']);
597 $shipment->setFieldNoDemand(
'PRICE_DELIVERY', floatval(
$requestFields[
'PRICE_DELIVERY']));
598 $shipment->setFieldNoDemand(
'BASE_PRICE_DELIVERY', floatval(
$requestFields[
'PRICE_DELIVERY']));
599 $shipment->setFieldNoDemand(
'CURRENCY',
$requestFields[
'CURRENCY']);
600 $shipment->setFieldNoDemand(
'CUSTOM_PRICE_DELIVERY',
"Y");
622 $countShipments = count($shipmentCollection);
623 $baseShipment =
null;
625 if ($countShipments <= 2 && $shipmentCollection->isExistsSystemShipment())
628 foreach ($shipmentCollection as $shipment)
630 if ($shipment->isSystem())
633 $baseShipment = $shipment;
642 if (!
$order = $shipmentCollection->getOrder())
644 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
648 if ($baseShipment ===
null)
653 if (isset(
$fields[
'ALLOW_DELIVERY']) && strval(
$fields[
'ALLOW_DELIVERY']) !=
'')
655 if ($baseShipment->getField(
'ALLOW_DELIVERY') !=
$fields[
'ALLOW_DELIVERY'])
657 if (
$fields[
'ALLOW_DELIVERY'] ==
"Y")
660 $r = $baseShipment->allowDelivery();
665 $r = $baseShipment->disallowDelivery();
670 $order->setFieldNoDemand(
'ALLOW_DELIVERY',
$fields[
'ALLOW_DELIVERY']);
674 $result->addErrors($r->getErrors());
680 if (isset(
$fields[
'DEDUCTED']) && strval(
$fields[
'DEDUCTED']) !=
'')
682 if ($baseShipment->getField(
'DEDUCTED') !=
$fields[
'DEDUCTED'])
684 if (
$fields[
'DEDUCTED'] ==
"Y")
687 $r = $baseShipment->tryShip();
692 $r = $baseShipment->tryUnship();
701 $result->addErrors($r->getErrors());
717 public function fillPaymentCollectionFromRequest(array
$fields)
722 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
726 if (!$paymentCollection =
$order->getPaymentCollection())
728 throw new Main\ObjectNotFoundException(
'Entity "PaymentCollection" not found');
731 $result =
new Sale\Result();
732 $sum = floatval(
$fields[
'PRICE']);
737 $sum = floatval(
$fields[
'SUM_PAID']);
740 $isPayFromUserBudget =
null;
741 $backToUserBudget =
null;
743 if (array_key_exists(
'ONLY_FULL_PAY_FROM_ACCOUNT',
$fields))
745 $isPayFromUserBudget =
$fields[
'ONLY_FULL_PAY_FROM_ACCOUNT'];
748 if ($isPayFromUserBudget ===
null && array_key_exists(
'PAY_CURRENT_ACCOUNT',
$fields) &&
$fields[
'PAY_CURRENT_ACCOUNT'] !==
null)
750 $isPayFromUserBudget = (
$fields[
'PAY_CURRENT_ACCOUNT'] !=
"Y");
753 if (array_key_exists(
'PAY_FROM_ACCOUNT_BACK',
$fields))
755 $backToUserBudget = (
$fields[
'PAY_FROM_ACCOUNT_BACK'] ==
"Y");
759 $paySystemName =
null;
762 $currency =
$order->getCurrency();
765 $paymentInner =
null;
766 $paymentOuter =
null;
767 $countPayments = count($paymentCollection);
771 if ((($countPayments == 0 &&
$order->getId() == 0)
772 || ($countPayments == 2 && $paymentCollection->isExistsInnerPayment())
773 || ($countPayments == 1 && !$paymentCollection->isExistsInnerPayment())))
778 if ($countPayments <= 1)
783 if (!isset(
$fields[
"PAY_SYSTEM_ID"]))
784 $fields[
"PAY_SYSTEM_ID"] = static::getDefaultPaySystemId(
$order->getPersonTypeId());
788 if ($service =
Sale\PaySystem\Manager::getObjectById(
$fields[
"PAY_SYSTEM_ID"]))
791 $paymentOuter = $paymentCollection->createItem($service);
792 $paymentOuter->setField(
'DATE_BILL',
new Main\
Type\DateTime());
793 $paymentOuter->setField(
'SUM', $needSum);
794 $paymentOuter->setField(
'PAY_SYSTEM_NAME', $service->getField(
'NAME'));
795 $order->setFieldNoDemand(
'PAY_SYSTEM_ID',
$fields[
"PAY_SYSTEM_ID"]);
801 $paymentOuter =
null;
804 foreach ($paymentCollection as $payment)
806 if ($payment->isInner())
809 $paymentOuter = $payment;
812 if ($paymentOuter !==
null
813 && ($paymentOuter->getPaymentSystemId() != intval(
$fields[
"PAY_SYSTEM_ID"]))
817 if ($service =
Sale\PaySystem\Manager::getObjectById(
$fields[
"PAY_SYSTEM_ID"]))
820 $paymentOuter->setField(
'PAY_SYSTEM_NAME', $service->getField(
'NAME'));
821 $paymentOuter->setField(
'PAY_SYSTEM_ID', intval(
$fields[
"PAY_SYSTEM_ID"]));
822 $order->setFieldNoDemand(
'PAY_SYSTEM_ID', intval(
$fields[
"PAY_SYSTEM_ID"]));
836 if ($countPayments > 0)
839 foreach($paymentCollection as $payment)
841 if ($paidFlag ===
null && $payment->isPaid() && $needSum == 0)
846 if ($payment->isInner())
849 $paymentOuter = $payment;
853 if ($paidFlag ===
null)
859 if ($paidFlag !=
$fields[
'PAYED'])
866 if ($isPayFromUserBudget !==
null)
868 if (static::canPayWithUserBudget($needSum, $userId, $currency, $isPayFromUserBudget))
870 $userBudget = Sale\Internals\UserBudgetPool::getUserBudget($userId, $currency);
872 if ($userBudget >= $needSum)
880 $r = static::payFromBudget(
$order, $pay, $isPayFromUserBudget);
888 $r = $paymentOuter->setField(
'SUM', $needSum);
891 if (!$r->isSuccess())
893 $result->addErrors($r->getErrors());
898 $result->addErrors($r->getErrors());
905 foreach($paymentCollection as $payment)
907 if ($payment->isPaid())
909 if ($backToUserBudget && $payment->isInner())
911 $payment->setReturn(
'Y');
915 $payment->setPaid(
'N');
919 if ($payment->isInner())
925 $payment->setField(
'SUM',
$order->getPrice());
934 elseif (
$order->getId() == 0)
936 if ($isPayFromUserBudget !==
null)
938 if (static::canPayWithUserBudget($needSum, $userId, $currency, $isPayFromUserBudget))
940 $userBudget = Sale\Internals\UserBudgetPool::getUserBudget($userId, $currency);
942 $setSum = $userBudget;
945 $r = static::payFromBudget(
$order,
false);
952 $result->addErrors($r->getErrors());
963 foreach($paymentCollection as $paymentItem)
965 if ($paymentItem->isInner())
967 $paymentInner = $paymentItem;
968 if ($payment ===
null && $paymentItem->isPaid())
970 $payment = $paymentItem;
975 $paymentOuter = $paymentItem;
976 if ($payment ===
null && $paymentItem->isPaid())
978 $payment = $paymentItem;
983 if ($payment ===
null)
985 if ($paymentOuter !==
null)
986 $payment = $paymentOuter;
988 $payment = $paymentInner;
991 if ($payment ===
null)
996 $paymentFields = static::convertDateFields(
$fields, static::getPaymentDateFields());
999 if (!empty($paymentFields[
'PAY_SYSTEM_ID']) && $paymentFields[
'PAY_SYSTEM_ID'] != $payment->getPaymentSystemId())
1001 if ($payment->isInner())
1003 unset($paymentFields[
'PAY_SYSTEM_ID']);
1007 $paySystemId = (int)$paymentFields[
'PAY_SYSTEM_ID'];
1010 if ($paysystem =
Sale\PaySystem\Manager::getObjectById($paySystemId))
1012 $paymentFields[
'PAY_SYSTEM_NAME'] = $paysystem->getField(
'NAME');
1018 $paymentFields = static::replaceFields($paymentFields, static::getPaymentReplaceFields());
1019 $paymentFields = static::clearFields($paymentFields, static::getPaymentAvailableFields());
1022 $r = $payment->setFields($paymentFields);
1023 if ($r->isSuccess())
1026 static::fillOrderFieldsFromEntity(
$order, $payment,
$fields, static::getPaymentFieldsToConvert());
1030 $result->addErrors($r->getErrors());
1034 if ($result->isSuccess() && intval($paySystemId) > 0)
1036 $order->setFieldNoDemand(
'PAY_SYSTEM_ID', $paySystemId);
1041 $paymentOuter =
null;
1044 foreach($paymentCollection as $payment)
1046 $calcSum += $payment->getSum();
1047 if ($payment->isInner())
1050 $paymentOuter = $payment;
1053 if ($paymentOuter && !$paymentOuter->isPaid())
1055 if (
$order->getPrice() != $calcSum)
1057 $paymentOuter->setField(
'SUM', $paymentOuter->getSum() + (
$order->getPrice() - $calcSum));
1064 $fieldsFromOrder = array(
1065 'PS_STATUS',
'PS_STATUS_CODE',
'PS_STATUS_DESCRIPTION',
1066 'PS_STATUS_MESSAGE',
'PS_SUM',
'PS_CURRENCY',
'PS_RESPONSE_DATE',
1067 'PAY_VOUCHER_NUM',
'PAY_VOUCHER_DATE',
'DATE_PAY_BEFORE',
1068 'DATE_BILL',
'PAY_SYSTEM_NAME',
'PAY_SYSTEM_ID',
1069 'DATE_PAYED',
'EMP_PAYED_ID',
'CURRENCY'
1072 foreach ($fieldsFromOrder as $fieldName)
1074 if (isset(
$fields[$fieldName]))
1079 case 'DATE_PAY_BEFORE':
1080 case 'PS_RESPONSE_DATE':
1081 if (!isset(
$fields[$fieldName]) || strval(
$fields[$fieldName]) ==
'')
1083 $value =
new Main\Type\DateTime(
$fields[$fieldName]);
1085 case 'PAY_VOUCHER_DATE':
1086 if (!isset(
$fields[$fieldName]) || strval(
$fields[$fieldName]) ==
'')
1088 $value =
new Main\Type\Date(
$fields[$fieldName]);
1091 if (!isset(
$fields[$fieldName]) || strval(
$fields[$fieldName]) ==
'')
1093 $fieldName =
'DATE_PAID';
1094 $value =
new Main\Type\DateTime(
$fields[
'DATE_PAYED']);
1096 case 'EMP_PAYED_ID':
1097 $fieldName =
'EMP_PAID_ID';
1098 $value =
$fields[
'EMP_PAYED_ID'];
1104 $paymentOuter->setFieldNoDemand($fieldName, $value);
1105 if ($fieldName ===
'PAY_SYSTEM_ID')
1107 $order->setFieldNoDemand(
'PAY_SYSTEM_ID', $value);
1110 if ($paysystem =
Sale\PaySystem\Manager::getObjectById($value))
1111 $paymentOuter->setFieldNoDemand(
'PAY_SYSTEM_NAME', $paysystem->getField(
'NAME'));
1114 if ($fieldName ==
"DATE_PAID")
1115 $fieldName =
'DATE_PAYED';
1119 $order->setFieldNoDemand($fieldName, $value);
1122 elseif (isset(
$fields[
'~'.$fieldName]))
1128 if (isset(
$fields[
'PAY_SYSTEM_PRICE']))
1129 $paymentOuter->setField(
'PRICE_COD',
$fields[
'PAY_SYSTEM_PRICE']);
1138 if (array_key_exists(
'SUM_PAID',
$fields))
1150 $oldSumPaid =
$order->getSumPaid();
1152 $deltaSumPaid = floatval(
$fields[
'SUM_PAID']) - $oldSumPaid;
1154 if ($deltaSumPaid > 0)
1156 $paidPayment =
false;
1159 foreach ($paymentCollection as $payment)
1161 if ($payment->isPaid() || $payment->isInner())
1166 $paidPayment =
true;
1168 $r = $payment->setPaid(
"Y");
1169 if (!$r->isSuccess())
1171 $result->addErrors($r->getErrors());
1180 $paymentSystemId =
null;
1182 if (count($paymentCollection) > 0)
1185 if ($firstPayment = $paymentCollection->rewind())
1187 $paymentSystemId = $firstPayment->getPaymentSystemId();
1188 if ($paymentSystemId > 0)
1190 $service = Sale\PaySystem\Manager::getObjectById($paymentSystemId);
1197 $paymentSystemId = static::getDefaultPaySystemId(
$order->getPersonTypeId());
1198 $service = Sale\PaySystem\Manager::getObjectById($paymentSystemId);
1205 $payment = $paymentCollection->createItem($service);
1206 $payment->setField(
'DATE_BILL',
new Main\
Type\DateTime());
1207 $payment->setField(
'SUM', $deltaSumPaid);
1208 $payment->setField(
'PAY_SYSTEM_NAME', $service->getField(
'NAME'));
1209 $order->setFieldNoDemand(
'PAY_SYSTEM_ID', $paymentSystemId);
1212 $r = $payment->setPaid(
"Y");
1213 if (!$r->isSuccess())
1215 $result->addErrors($r->getErrors());
1226 private static function getDefaultPaySystemId($personTypeId)
1228 $personTypeId = intval($personTypeId);
1230 static $defaultPaySystemId = array();
1231 if (isset($defaultPaySystemId[$personTypeId]))
1232 return $defaultPaySystemId[$personTypeId];
1234 $defaultPaySystemId[$personTypeId] = intval(Main\
Config\Option::get(
'sale',
'1C_IMPORT_DEFAULT_PS', 0));
1235 if (isset($defaultPaySystemId[$personTypeId]) && ($defaultPaySystemId[$personTypeId] > 0))
1236 return $defaultPaySystemId[$personTypeId];
1238 if ($personTypeId > 0)
1240 $dbPaySystem = Sale\PaySystem\Manager::getList(
1242 'select' => array(
"ID"),
1245 '=PERSON_TYPE_ID' => $personTypeId,
1246 '=ENTITY_REGISTRY_TYPE' => static::getRegistryType()
1248 'order' => array(
'SORT'),
1252 if ($paySystem = $dbPaySystem->fetch())
1253 $defaultPaySystemId[$personTypeId] = intval($paySystem[
'ID']);
1255 if (isset($defaultPaySystemId[$personTypeId]) && ($defaultPaySystemId[$personTypeId] > 0))
1256 return $defaultPaySystemId[$personTypeId];
1259 $dbPaySystem = Sale\PaySystem\Manager::getList(
1261 'select' => array(
"ID"),
1264 '=ENTITY_REGISTRY_TYPE' => static::getRegistryType()
1266 'order' => array(
'SORT'),
1270 if ($paySystem = $dbPaySystem->fetch())
1271 $defaultPaySystemId[$personTypeId] = intval($paySystem[
'ID']);
1273 return $defaultPaySystemId[$personTypeId];
1283 public function fillTaxFromRequest(
Sale\Tax $tax, array
$fields)
1285 if (!empty(
$fields[
'COUNT_DELIVERY_TAX']))
1287 $tax->setDeliveryCalculate((
$fields[
'COUNT_DELIVERY_TAX'] ==
"Y"));
1290 if (!empty(
$fields[
'TAX_LIST']) && is_array(
$fields[
'TAX_LIST']))
1292 $tax->initTaxList(
$fields[
'TAX_LIST']);
1294 elseif (!empty($tax->getTaxList()))
1299 $order->refreshVat();
1300 if ($tax =
$order->getTax())
1302 $tax->resetTaxList();
1307 if (array_key_exists(
'TAX_VALUE',
$fields))
1310 $order->setFieldNoDemand(
'TAX_VALUE', floatval(
$fields[
'TAX_VALUE']));
1313 return new Sale\Result();
1325 public static function shipment($id, $value, array $storeData = array() )
1329 $result =
new Sale\Result();
1331 $registry = Sale\Registry::getInstance(static::getRegistryType());
1334 $orderClassName = $registry->getOrderClassName();
1335 if (
$order = $orderClassName::load($id))
1340 throw new Main\ObjectNotFoundException(
'Entity "Basket" not found');
1344 if(!$shipmentCollection =
$order->getShipmentCollection())
1346 throw new Main\ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
1350 foreach ($shipmentCollection as $shipment)
1352 if ($shipment->isSystem())
1356 if (!$shipmentItemCollection = $shipment->getShipmentItemCollection())
1358 throw new Main\ObjectNotFoundException(
'Entity "ShipmentItemCollection" not found');
1362 $r = static::fillShipmentItemCollectionFromRequest($shipmentItemCollection, $storeData,
$basket);
1363 if (!$r->isSuccess())
1365 $result->addErrors($r->getErrors());
1370 $r = $shipment->setField(
'DEDUCTED', $value ===
true ?
'Y' :
'N');
1371 if (!$r->isSuccess())
1373 $result->addErrors($r->getErrors());
1382 if (!$r->isSuccess())
1384 $result->addErrors($r->getErrors());
1400 public static function fillShipmentItemCollectionFromRequest(
Sale\ShipmentItemCollection $shipmentItemCollection, array $storeData,
Sale\Basket
$basket =
null)
1402 $result =
new Sale\Result();
1409 if (!$shipment = $shipmentItemCollection->getShipment())
1411 throw new Main\ObjectNotFoundException(
'Entity "Shipment" not found');
1416 if(!$shipmentCollection = $shipment->getCollection())
1418 throw new Main\ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
1422 if (!
$order = $shipmentCollection->getOrder())
1424 throw new Main\ObjectNotFoundException(
'Entity "Order" not found');
1430 throw new Main\ObjectNotFoundException(
'Entity "Basket" not found');
1435 foreach ($shipmentItemCollection as $shipmentItem)
1438 if (($basketItem = $shipmentItem->getBasketItem()) && $basketItem->getId() == 0)
1443 $shipmentItemStoreCollection = $shipmentItem->getShipmentItemStoreCollection();
1445 !$shipmentItemStoreCollection
1446 && $basketItem->isReservableItem()
1449 throw new Main\ObjectNotFoundException(
'Entity "ShipmentItemStoreCollection" not found');
1452 $barcodeList = array();
1454 foreach ($shipmentItemStoreCollection as $shipmentItemStore)
1456 $storeId = $shipmentItemStore->getField(
'STORE_ID');
1457 $basketId = $shipmentItemStore->getField(
'BASKET_ID');
1458 $barcodeList[$basketId][
$storeId][] = array(
1459 'ID' => $shipmentItemStore->getId(),
1460 'QUANTITY' => $shipmentItemStore->getQuantity(),
1461 'BARCODE' => $shipmentItemStore->getBarcode(),
1465 $baseBarcode =
null;
1467 foreach($storeData as $basketId => $barcodeDataList)
1469 if ((intval($basketId) != $basketId)
1470 || ($basketItem->getId() != $basketId))
1473 foreach ($barcodeDataList as $barcodeData)
1477 if (!$basketItem =
$basket->getItemById($basketId))
1479 throw new Main\ObjectNotFoundException(
'Entity "BasketItem" not found');
1483 $saveBarcodeList = array();
1485 if ($basketItem->isBarcodeMulti() && is_array($barcodeData[
'BARCODE']))
1487 $barcodeQuantity = $barcodeData[
'QUANTITY'] / count($barcodeData[
'BARCODE']);
1489 foreach ($barcodeData[
'BARCODE'] as $barcodeId => $barcodeValue)
1491 $barcodeFields = array(
1492 'QUANTITY' => $barcodeQuantity,
1493 'BARCODE' => $barcodeValue,
1496 if (intval($barcodeId) > 0)
1498 $barcodeFields[
'ID'] = intval($barcodeId);
1501 $saveBarcodeList[] = $barcodeFields;
1506 if (strval($barcodeData[
'BARCODE']) !=
'')
1508 $baseBarcode = trim($barcodeData[
'BARCODE']);
1510 elseif (!empty($baseBarcode))
1512 $barcodeData[
'BARCODE'] = $baseBarcode;
1515 $barcodeFields = array(
1516 'QUANTITY' => $barcodeData[
'QUANTITY'],
1517 'BARCODE' => $barcodeData[
'BARCODE'],
1520 if (!empty($barcodeList[$basketId]) && !empty($barcodeList[$basketId][$barcodeData[
'STORE_ID']]))
1523 foreach ($barcodeList[$basketId][$barcodeData[
'STORE_ID']] as $existBarcodeData)
1525 if ($existBarcodeData[
'BARCODE'] == $barcodeData[
'BARCODE'] && !empty($existBarcodeData[
'ID']))
1527 if ($shipmentItemStoreCollection->getItemById($existBarcodeData[
'ID']))
1529 $barcodeFields[
'ID'] = $existBarcodeData[
'ID'];
1535 $saveBarcodeList = array(
1540 foreach ($saveBarcodeList as $saveBarcodeData)
1542 $barcodeFields = array(
1543 'QUANTITY' => $saveBarcodeData[
'QUANTITY'],
1544 'BARCODE' => $saveBarcodeData[
'BARCODE'],
1548 $shipmentItemStore = $shipmentItemStoreCollection->getItemByBarcode($saveBarcodeData[
'BARCODE']);
1550 if (!$shipmentItemStore)
1552 $barcodeFields[
'STORE_ID'] = intval($barcodeData[
'STORE_ID']);
1553 $shipmentItemStore = $shipmentItemStoreCollection->createItem($basketItem);
1557 $r = $shipmentItemStore->setFields($barcodeFields);
1558 if (!$r->isSuccess())
1560 $result->addErrors($r->getErrors());
1578 public static function allowDelivery($id, $value)
1580 $result =
new Sale\Result();
1582 $registry = Sale\Registry::getInstance(static::getRegistryType());
1585 $orderClassName = $registry->getOrderClassName();
1586 if (
$order = $orderClassName::load($id))
1589 if(!$shipmentCollection =
$order->getShipmentCollection())
1591 throw new Main\ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
1595 foreach ($shipmentCollection as $shipment)
1597 if ($shipment->isSystem())
1601 $r = $shipment->setField(
'ALLOW_DELIVERY', $value ===
true ?
'Y' :
'N');
1602 if (!$r->isSuccess())
1604 $result->addErrors($r->getErrors());
1613 if (!$r->isSuccess())
1615 $result->addErrors($r->getErrors());
1628 return static::modifyOrder(static::ORDER_COMPAT_ACTION_ADD,
$fields);
1638 public static function update($id, array
$fields, $dateUpdate =
false)
1646 $result->addError(
new Sale\
ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND'),
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND'));
1654 $fields[
'DATE_UPDATE'] =
null;
1658 return static::modifyOrder(static::ORDER_COMPAT_ACTION_UPDATE,
$fields);
1670 public static function modifyOrder($action, array
$fields)
1672 $result =
new Sale\Result();
1676 $adminSection = (defined(
'ADMIN_SECTION') && ADMIN_SECTION ===
true);
1679 $orderCompatibility = static::create(
$fields);
1682 $order = $orderCompatibility->getOrder();
1685 $propCollection =
$order->getPropertyCollection();
1687 if (!empty(
$fields[
'ORDER_PROP']) && is_array(
$fields[
'ORDER_PROP']))
1692 if (!isset(
$fields[
'PROPERTIES']) || !is_array(
$fields[
'PROPERTIES']))
1694 $fields[
'PROPERTIES'] = array();
1699 foreach ($propCollection as $propertyValue)
1701 $propertyFields = $propertyValue->getProperty();
1702 $key = isset($propertyFields[
'ID']) ? $propertyFields[
'ID'] :
'n'.$propertyValue->getId();
1704 if ($propertyValue->getId() <=0
1705 && !array_key_exists($key,
$fields[
'PROPERTIES'])
1708 $propertyValue->delete();
1713 $r = $propCollection->setValuesFromPost(
$fields, $_FILES);
1714 if (!$r->isSuccess())
1716 $result->addErrors($r->getErrors());
1721 $oldPrice =
$order->getPrice();
1729 if (!
$basket && $action == static::ORDER_COMPAT_ACTION_SAVE)
1734 if (!empty(
$fields[
'BASKET_ITEMS']) && is_array(
$fields[
'BASKET_ITEMS']))
1736 foreach (
$fields[
'BASKET_ITEMS'] as $basketItemData)
1738 if (!empty($basketItemData[
'FUSER_ID']) && intval($basketItemData[
'FUSER_ID']) > 0)
1740 $fUserId = intval($basketItemData[
'FUSER_ID']);
1747 if (intval($fUserId) <= 0 && !$adminSection)
1749 $fUserId = static::getDefaultFuserId();
1755 $fUserIdByUserId = Sale\Fuser::getIdByUserId($userId);
1756 if (intval($fUserId) > 0 && intval($fUserIdByUserId) > 0
1757 && intval($fUserId) != intval($fUserIdByUserId))
1760 \CSaleBasket::TransferBasket($fUserId, $fUserIdByUserId);
1763 $fUserId = $fUserIdByUserId;
1766 if (intval($fUserId) <= 0)
1768 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_FUSERID_NOT_FOUND'),
"SALE_COMPATIBLE_ORDER_FUSERID_NOT_FOUND"));
1773 $registry = Sale\Registry::getInstance(static::getRegistryType());
1775 $basketClassName = $registry->getBasketClassName();
1780 $allBasket = $basketClassName::loadItemsForFUser($fUserId, $siteId);
1784 $basket = $allBasket->getOrderableItems();
1792 $basket->setFUserId($fUserId);
1796 $isStartField =
$order->isStartField(
true);
1802 $basketCompatibilityClassName = static::getBasketCompatibilityClassName();
1803 $basketCompatibility = $basketCompatibilityClassName::create($orderCompatibility);
1807 if (!$r->isSuccess())
1809 $result->addErrors($r->getErrors());
1813 if ($action == static::ORDER_COMPAT_ACTION_SAVE &&
$order->getId() == 0 && count(
$basket) > 0)
1815 $order->setMathActionOnly(
true);
1817 $order->setMathActionOnly(
false);
1820 if ($orderCompatibility->isExistPrice() && $oldPrice ==
$order->getPrice())
1822 $order->setFieldNoDemand(
'PRICE', $orderCompatibility->externalPrice);
1828 $r = $orderCompatibility->fillTaxFromRequest(
$order->getTax(),
$fields);
1829 if (!$r->isSuccess())
1831 $result->addErrors($r->getErrors());
1836 $r = $orderCompatibility->fillShipmentCollectionFromRequest(
$order->getShipmentCollection(),
$fields);
1837 if (!$r->isSuccess())
1839 $result->addErrors($r->getErrors());
1845 $hasMeaningfulFields =
$order->hasMeaningfulField();
1848 $r =
$order->doFinalAction($hasMeaningfulFields);
1849 if (!$r->isSuccess())
1851 $result->addErrors($r->getErrors());
1856 $order->setMathActionOnly(
false);
1859 $r = $orderCompatibility->fillPaymentCollectionFromRequest(
$fields);
1860 if (!$r->isSuccess())
1862 $result->addErrors($r->getErrors());
1868 if (!$r->isSuccess())
1870 $result->addErrors($r->getErrors());
1875 catch(
Sale\UserMessageException $e)
1877 $result->addError(
new Sale\ResultError($e->getMessage(), $e->getCode()));
1881 static::transformationLocation(
$order);
1885 if ($r->isSuccess())
1887 if ($orderData = $r->getData())
1888 $result->setData($orderData);
1890 if ($orderId = $r->getId())
1891 $result->setId($orderId);
1894 $r = $orderCompatibility->saveRawFields(
$order, static::ENTITY_ORDER);
1897 if (!$r->isSuccess())
1899 $result->addErrors($r->getErrors());
1903 $oldFields = static::convertDateFieldsToOldFormat(
$order->getFieldValues());
1904 $oldFields = $oldFields + $orderCompatibility->rawFields;
1907 if ($paymentCollection =
$order->getPaymentCollection())
1910 foreach ($paymentCollection as $payment)
1912 if ($payment->getId() <= 0)
1918 $r = $orderCompatibility->saveRawFields($payment, static::ENTITY_PAYMENT);
1919 if (!$r->isSuccess())
1921 $result->addErrors($r->getErrors());
1926 $result->setData(array(
1927 'OLD_FIELDS' => $oldFields
1941 public static function reserve($orderId, $value)
1943 $result =
new Sale\Result();
1945 $registry = Sale\Registry::getInstance(static::getRegistryType());
1948 $orderClassName = $registry->getOrderClassName();
1949 if (!
$order = $orderClassName::load($orderId))
1951 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_NOT_FOUND'),
'SALE_COMPATIBLE_ORDER_NOT_FOUND') );
1956 if (!$shipmentCollection =
$order->getShipmentCollection())
1958 throw new Main\ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
1962 foreach ($shipmentCollection as $shipment)
1964 if ($shipment->isSystem())
1970 $r = $shipment->tryReserve();
1971 if (!$r->isSuccess())
1973 $registry = Sale\Registry::getInstance(static::getRegistryType());
1976 $entityMarkerClassName = $registry->getEntityMarkerClassName();
1977 $entityMarkerClassName::addMarker(
$order, $shipment, $r);
1978 if (!$shipment->isSystem())
1980 $shipment->setField(
'MARKED',
'Y');
1983 $result->addErrors($r->getErrors());
1988 if (!$shipment->isShipped())
1991 $r = $shipment->tryUnreserve();
1992 if (!$r->isSuccess())
1994 $registry = Sale\Registry::getInstance(static::getRegistryType());
1997 $entityMarkerClassName = $registry->getEntityMarkerClassName();
1998 $entityMarkerClassName::addMarker(
$order, $shipment, $r);
1999 if (!$shipment->isSystem())
2001 $shipment->setField(
'MARKED',
'Y');
2003 $result->addErrors($r->getErrors());
2011 if (!$r->isSuccess())
2013 $result->addErrors($r->getErrors());
2028 public static function pay($orderId, array $values, $withdraw =
false, $pay =
false)
2030 $result =
new Sale\Result();
2033 if (isset($values[
'PAYED']) && strval($values[
'PAYED']) !=
'')
2035 $values[
'PAID'] = $values[
'PAYED'];
2038 if (intval($orderId) <= 0)
2040 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND'),
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND') );
2044 $registry = Sale\Registry::getInstance(static::getRegistryType());
2046 $orderClassName = $registry->getOrderClassName();
2047 if (!
$order = $orderClassName::load($orderId))
2049 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_NOT_FOUND'),
'SALE_COMPATIBLE_ORDER_NOT_FOUND') );
2053 if (
$order->isCanceled())
2056 $r =
$order->setField(
'CANCELED',
'N');
2057 if (!$r->isSuccess())
2059 $result->addErrors($r->getErrors());
2065 if (!$paymentCollection =
$order->getPaymentCollection())
2067 throw new Main\ObjectNotFoundException(
'Entity "PaymentCollection" not found');
2070 $paidFormUserBudget =
false;
2075 $r = static::payFromBudget(
$order, $pay);
2076 if (!$r->isSuccess())
2078 $result->addErrors($r->getErrors());
2082 $payBudgetData = $r->getData();
2083 if (array_key_exists(
'PAID_FROM_BUDGET', $payBudgetData))
2085 $paidFormUserBudget = $payBudgetData[
'PAID_FROM_BUDGET'];
2092 if (!$paidFormUserBudget)
2095 foreach ($paymentCollection as $payment)
2099 if (isset($values[
'=DATE_PAYED']))
2101 $values[
'DATE_PAID'] = $values[
'=DATE_PAYED'];
2102 unset($values[
'=DATE_PAYED']);
2105 $values = static::convertDateFields($values, static::getPaymentDateFields());
2106 $fields = static::clearFields($values, $payment->getAvailableFields());
2110 if ($values[
'PAID'] ==
"N" && !$payment->isPaid())
2113 if ($withdraw && $values[
'PAID'] ==
"N" && $payment->isInner())
2116 $r = $payment->setReturn(
'Y');
2117 if (!$r->isSuccess())
2119 $result->addErrors($r->getErrors());
2124 $oldPaid = $payment->isPaid();
2126 $r = $payment->setPaid($values[
'PAID']);
2127 if (!$r->isSuccess())
2129 $result->addErrors($r->getErrors());
2132 if ($payment->isInner() && !$oldPaid && $payment->isPaid())
2135 if (!$r->isSuccess())
2137 $result->addErrors($r->getErrors());
2148 $r = $payment->setFields(
$fields);
2149 if (!$r->isSuccess())
2151 $result->addErrors($r->getErrors());
2156 if (!$result->isSuccess())
2163 if (!$r->isSuccess())
2165 $result->addErrors($r->getErrors());
2181 public static function payFromBudget(
Sale\Order
$order, $pay, $paidFormUserBudget =
null)
2183 $result =
new Sale\Result();
2186 $paymentInner =
null;
2189 $paymentOuter =
null;
2192 if (!$paymentCollection =
$order->getPaymentCollection())
2194 throw new Main\ObjectNotFoundException(
'Entity "PaymentCollection" not found');
2197 if (count($paymentCollection) > 2)
2206 foreach ($paymentCollection as $payment)
2208 if (!$payment->isInner())
2210 $paymentOuter = $payment;
2215 if (!$pay || ($pay && $paidFormUserBudget ===
false))
2218 $paymentInner = $paymentCollection->getInnerPayment();
2221 $paymentInner = $paymentCollection->createInnerPayment();
2226 throw new Main\ObjectNotFoundException(
'Entity inner "Payment" not found');
2229 $userBudget = Sale\Internals\UserBudgetPool::getUserBudget(
$order->getUserId(),
$order->getCurrency());
2231 $setSum = $userBudget;
2232 if ($userBudget >= $needSum)
2237 if ($paymentInner->getId() == 0)
2239 $paymentInnerFields = array(
2241 'CURRENCY' =>
$order->getCurrency(),
2242 'DATE_BILL' =>
new Main\
Type\DateTime(),
2245 $r = $paymentInner->setFields($paymentInnerFields);
2246 if (!$r->isSuccess())
2248 $result->addErrors($r->getErrors());
2253 if ($paymentInner->getSum() < $needSum)
2255 $paymentInner->setField(
'SUM', $needSum - $paymentInner->getSum());
2259 if ($pay && $paidFormUserBudget ===
false)
2261 $paymentOuter->setField(
'SUM', $needSum - $setSum);
2264 $payment = $paymentInner;
2269 $payment = $paymentOuter;
2275 if ($payment ===
null)
2277 $paySystemId = static::getDefaultPaySystemId(
$order->getPersonTypeId());
2280 if ($paySystem =
Sale\PaySystem\Manager::getObjectById($paySystemId))
2282 $registry = Sale\Registry::getInstance(static::getRegistryType());
2284 $paymentClassName = $registry->getPaymentClassName();
2286 $payment = $paymentClassName::create($paymentCollection, $paySystem);
2287 $payment->setField(
'SUM', $needSum);
2288 $payment->setField(
'DATE_BILL',
new Main\
Type\DateTime());
2289 $paymentCollection->addItem($payment);
2293 $operationPayment = $payment;
2294 if ($paidFormUserBudget ===
false)
2296 $operationPayment = $paymentOuter;
2299 $service = Sale\PaySystem\Manager::getObjectById($operationPayment->getPaymentSystemId());
2302 $r = $service->creditNoDemand($operationPayment);
2303 if (!$r->isSuccess())
2304 $result->addErrors($r->getErrors());
2308 $result->addError(
new Main\Entity\EntityError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_PAYSYSTEM_NOT_FOUND')));
2313 if ($payment->isReturn() && $payment->isInner())
2315 $r = $payment->setPaid(
'Y');
2320 $r = $payment->setPaid(
'Y');
2322 if ($r->isSuccess())
2326 $operationPayment = $payment;
2327 if ($paidFormUserBudget ===
false)
2329 $operationPayment = $paymentOuter;
2332 $resultPayment = $paymentOuter->setPaid(
'Y');
2333 if (!$resultPayment->isSuccess())
2335 $result->addErrors($resultPayment->getErrors());
2339 $service = Sale\PaySystem\Manager::getObjectById($operationPayment->getPaymentSystemId());
2342 $r = $service->creditNoDemand($operationPayment);
2343 if (!$r->isSuccess())
2344 $result->addErrors($r->getErrors());
2348 $result->addError(
new Main\Entity\EntityError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_PAYSYSTEM_NOT_FOUND')));
2356 $result->addErrors($r->getErrors());
2360 if (!$r->isSuccess())
2362 $result->addErrors($r->getErrors());
2367 $result->setData(array(
'PAID_FROM_BUDGET' => $paidFormUserBudget));
2381 public static function cancel($orderId, $value, $comment =
false)
2383 $result =
new Sale\Result();
2385 if (intval($orderId) <= 0)
2387 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND'),
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND') );
2391 $registry = Sale\Registry::getInstance(static::getRegistryType());
2393 $orderClassName = $registry->getOrderClassName();
2394 if (!
$order = $orderClassName::load($orderId))
2396 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_NOT_FOUND'),
'SALE_COMPATIBLE_ORDER_NOT_FOUND') );
2402 if (
$order->isCanceled())
2404 $r =
$order->setField(
'CANCELED',
'N');
2405 if (!$r->isSuccess())
2407 return $result->addErrors($r->getErrors());
2411 if (!$r->isSuccess())
2413 return $result->addErrors($r->getErrors());
2420 if (
$order->isCanceled())
2425 $paymentCollection =
$order->getPaymentCollection();
2427 foreach ($paymentCollection as $payment)
2429 if ($payment->isPaid())
2430 $payment->setReturn(
'Y');
2433 $shipmentCollection =
$order->getShipmentCollection();
2435 foreach ($shipmentCollection as $shipment)
2437 if ($shipment->isSystem())
2440 if ($shipment->isShipped())
2441 $shipment->setField(
'DEDUCTED',
'N');
2443 if ($shipment->isAllowDelivery())
2444 $shipment->disallowDelivery();
2447 $r =
$order->setField(
'CANCELED',
'Y');
2448 if (!$r->isSuccess())
2450 return $result->addErrors($r->getErrors());
2453 if (!empty($comment) && strval($comment) !=
'')
2455 $r =
$order->setField(
'REASON_CANCELED', $comment);
2456 if (!$r->isSuccess())
2458 return $result->addErrors($r->getErrors());
2471 public static function delete($id)
2473 $result =
new Sale\Result();
2475 if (intval($id) <= 0)
2477 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND'),
'SALE_COMPATIBLE_ORDER_ID_NOT_FOUND') );
2481 $registry = Sale\Registry::getInstance(static::getRegistryType());
2483 $orderClassName = $registry->getOrderClassName();
2484 if (!
$order = $orderClassName::load($id))
2486 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_ORDER_ENTITY_NOT_FOUND'),
'SALE_ORDER_ENTITY_NOT_FOUND'));
2491 foreach (
$order->getPaymentCollection() as $payment)
2493 if ($payment->isPaid())
2495 $payment->setPaid(
'N');
2500 foreach (
$order->getShipmentCollection() as $shipment)
2502 if ($shipment->isShipped())
2504 $shipment->setField(
'DEDUCTED',
'N');
2509 if (!$r->isSuccess())
2511 $result->addErrors($r->getErrors());
2517 $r = $orderClassName::delete($id);
2519 catch (\Exception $exception)
2521 $r = $orderClassName::deleteNoDemand($id);
2524 if (!$r->isSuccess())
2526 $result->addErrors($r->getErrors());
2541 $budget = Sale\Internals\UserBudgetPool::getUserBudget($userId, $currency);
2542 if ($fullPay ===
false && $budget > 0)
2545 if ($fullPay ===
true && $budget >= $needSum)
2564 $systemShipment = $shipmentCollection->getSystemShipment();
2566 if ($systemShipment->getDeliveryId() > 0)
2569 $shipment = static::getShipmentByDeliveryId($shipmentCollection, $systemShipment->getDeliveryId());
2573 if ($service =
Sale\
Delivery\Services\Manager::getObjectById($systemShipment->getDeliveryId()))
2576 $shipment = $shipmentCollection->createItem($service);
2577 $shipment->setField(
'DELIVERY_NAME', $service->getName());
2593 public static function getShipmentByDeliveryId(
Sale\ShipmentCollection $shipmentCollection, $deliveryId)
2596 foreach($shipmentCollection as $shipment)
2598 if ($shipment->isSystem())
2601 if ($shipment->getDeliveryId() == $deliveryId)
2613 protected static function transformationLocation(
Sale\Order
$order)
2616 if ($propertyCollection =
$order->getPropertyCollection())
2619 foreach ($propertyCollection as $valueItem)
2621 if ($valueItem->getValue() !=
'')
2623 $setValue = $valueItem->getValue();
2625 $prop = $valueItem->getPropertyObject();
2626 if ($prop->getType() ==
'LOCATION')
2628 $setValue = \CSaleLocation::tryTranslateIDToCode($setValue);
2631 $valueItem->setField(
'VALUE', $setValue);
2645 public static function getById($id)
2647 $compatibility =
new static();
2651 $registry = Sale\Registry::getInstance(static::getRegistryType());
2653 $orderClassName = $registry->getOrderClassName();
2655 if (
$order = $orderClassName::load($id))
2658 if ($paymentCollection =
$order->getPaymentCollection())
2660 if (count($paymentCollection) == 1)
2662 $select = array_merge(
$select, array_keys(static::getAliasPaymentFields()));
2667 if ($shipmentCollection =
$order->getShipmentCollection())
2669 if (count($shipmentCollection) == 1
2670 || (count($shipmentCollection) == 2 && $shipmentCollection->isExistsSystemShipment()))
2672 $select = array_merge(
$select, array_keys(static::getAliasShipmentFields()));
2677 return static::setGetListParameters($compatibility, array(), array(
"ID" => $id),
null, array(),
$select);
2687 'NAME_SEARCH' => array(
2688 'NAME' =>
'USER.NAME',
2689 'LAST_NAME' =>
'USER.LAST_NAME',
2690 'SECOND_NAME' =>
'USER.SECOND_NAME',
2691 'EMAIL' =>
'USER.EMAIL',
2692 'LOGIN' =>
'USER.LOGIN',
2693 'NAME_SEARCH' =>
'USER.ID',
2695 'USER_ID' =>
'USER.ID',
2696 'USER_LOGIN' =>
'USER.LOGIN',
2697 'USER_NAME' =>
'USER.NAME',
2698 'USER_LAST_NAME' =>
'USER.LAST_NAME',
2699 'USER_EMAIL' =>
'USER.EMAIL',
2700 'RESPONSIBLE_ID' =>
'RESPONSIBLE.ID',
2701 'RESPONSIBLE_LOGIN' =>
'RESPONSIBLE.LOGIN',
2702 'RESPONSIBLE_NAME' =>
'RESPONSIBLE.NAME',
2703 'RESPONSIBLE_LAST_NAME' =>
'RESPONSIBLE.LAST_NAME',
2704 'RESPONSIBLE_SECOND_NAME' =>
'RESPONSIBLE.SECOND_NAME',
2705 'RESPONSIBLE_EMAIL' =>
'RESPONSIBLE.EMAIL',
2706 'RESPONSIBLE_WORK_POSITION' =>
'RESPONSIBLE.WORK_POSITION',
2707 'RESPONSIBLE_PERSONAL_PHOTO' =>
'RESPONSIBLE.PERSONAL_PHOTO',
2709 'PROPERTY_ID' =>
'PROPERTY.ID',
2710 'PROPERTY_ORDER_PROPS_ID' =>
'PROPERTY.ORDER_PROPS_ID',
2711 'PROPERTY_NAME' =>
'PROPERTY.NAME',
2712 'PROPERTY_VALUE' =>
'PROPERTY.VALUE',
2713 'PROPERTY_CODE' =>
'PROPERTY.CODE',
2714 'PROPERTY_VAL_BY_CODE' =>
'PROPERTY.VALUE',
2720 static::getAliasPaymentFields(),
2721 static::getAliasShipmentFields(),
2722 static::getAliasBasketFields()
2732 'PAY_SYSTEM_ID' =>
'PAYMENT.PAY_SYSTEM_ID',
2733 'PAYED' =>
'PAYMENT.PAID',
2735 'DATE_PAYED' =>
'PAYMENT.DATE_PAID',
2736 'EMP_PAYED_ID' =>
'PAYMENT.EMP_PAID_ID',
2738 'PS_STATUS' =>
'PAYMENT.PS_STATUS',
2739 'PS_STATUS_CODE' =>
'PAYMENT.PS_STATUS_CODE',
2740 'PS_STATUS_DESCRIPTION' =>
'PAYMENT.PS_STATUS_DESCRIPTION',
2741 'PS_STATUS_MESSAGE' =>
'PAYMENT.PS_STATUS_MESSAGE',
2742 'PS_SUM' =>
'PAYMENT.PS_SUM',
2743 'PS_CURRENCY' =>
'PAYMENT.PS_CURRENCY',
2744 'PS_RESPONSE_DATE' =>
'PAYMENT.PS_RESPONSE_DATE',
2754 'DELIVERY_ID' =>
'SHIPMENT.DELIVERY.CODE',
2756 'PRICE_DELIVERY' =>
'SHIPMENT.PRICE_DELIVERY',
2757 'ALLOW_DELIVERY' =>
'SHIPMENT.ALLOW_DELIVERY',
2758 'DATE_ALLOW_DELIVERY' =>
'SHIPMENT.DATE_ALLOW_DELIVERY',
2759 'EMP_ALLOW_DELIVERY_ID' =>
'SHIPMENT.EMP_ALLOW_DELIVERY_ID',
2761 'DATE_DEDUCTED' =>
'SHIPMENT.DATE_DEDUCTED',
2762 'EMP_DEDUCTED_ID' =>
'SHIPMENT.EMP_DEDUCTED_ID',
2763 'REASON_UNDO_DEDUCTED' =>
'SHIPMENT.REASON_UNDO_DEDUCTED',
2765 'TRACKING_NUMBER' =>
'SHIPMENT.TRACKING_NUMBER',
2766 'DELIVERY_DOC_NUM' =>
'SHIPMENT.DELIVERY_DOC_NUM',
2767 'DELIVERY_DOC_DATE' =>
'SHIPMENT.DELIVERY_DOC_DATE',
2777 'BASKET_ID' =>
'BASKET.ID',
2778 'BASKET_PRODUCT_ID' =>
'BASKET.PRODUCT_ID',
2779 'BASKET_PRODUCT_XML_ID' =>
'BASKET.PRODUCT_XML_ID',
2780 'BASKET_MODULE' =>
'BASKET.MODULE',
2781 'BASKET_NAME' =>
'BASKET.NAME',
2782 'BASKET_QUANTITY' =>
'BASKET.QUANTITY',
2783 'BASKET_PRICE' =>
'BASKET.PRICE',
2784 'BASKET_CURRENCY' =>
'BASKET.CURRENCY',
2785 'BASKET_VAT_RATE' =>
'BASKET.VAT_RATE',
2786 'BASKET_RECOMMENDATION' =>
'BASKET.RECOMMENDATION',
2787 'BASKET_DISCOUNT_PRICE' =>
'BASKET.DISCOUNT_PRICE',
2788 'BASKET_DISCOUNT_NAME' =>
'BASKET.DISCOUNT_NAME',
2789 'BASKET_DISCOUNT_VALUE' =>
'BASKET.DISCOUNT_VALUE',
2798 $fields = array_keys(static::getEntity()->getScalarFields());
2800 return array_merge(
$fields, array(
2801 'DATE_INSERT_FORMAT',
2802 'DATE_UPDATE_SHORT',
2803 'DATE_STATUS_SHORT',
2804 'DATE_CANCELED_SHORT',
2805 'BY_RECOMMENDATION',
2809 'DATE_INSERT_FORMAT',
2812 "RESPONSIBLE_LOGIN",
2814 "RESPONSIBLE_LAST_NAME",
2815 "RESPONSIBLE_SECOND_NAME",
2816 "RESPONSIBLE_EMAIL",
2817 "RESPONSIBLE_WORK_POSITION",
2818 "RESPONSIBLE_PERSONAL_PHOTO",
2819 "RESPONSIBLE_GROUP_ID",
2827 "DATE_ALLOW_DELIVERY",
2828 "EMP_ALLOW_DELIVERY_ID",
2830 "DELIVERY_DOC_DATE",
2837 "DATE_INSERT_FORMAT",
2858 $registry = Sale\Registry::getInstance(static::getRegistryType());
2860 $orderClassName = $registry->getOrderClassName();
2862 return array_merge($orderClassName::getAvailableFields(),
2863 array(
'PRICE_DELIVERY',
"PAY_VOUCHER_DATE",
"PAY_VOUCHER_NUM",
"DATE_ALLOW_DELIVERY",
"DATE_PAYED")
2904 protected static function getPaymentAvailableFields()
2906 $registry = Sale\Registry::getInstance(static::getRegistryType());
2908 $paymentClassName = $registry->getPaymentClassName();
2910 return static::clearAvailableFields($paymentClassName::getAvailableFields(), static::getPaymentClearFields());
2916 protected static function getShipmentAvailableFields()
2918 $registry = Sale\Registry::getInstance(static::getRegistryType());
2920 $shipmentClassName = $registry->getShipmentClassName();
2922 return static::clearAvailableFields($shipmentClassName::getAvailableFields(), static::getShipmentClearFields());
2928 return array_merge(parent::getWhiteListFields(), array_keys(static::getAliasFields()));
2941 if (!empty($clearFields))
2945 if (!in_array($field, $clearFields))
2961 static::getShipmentFieldsToConvert(),
2962 static::getPaymentFieldsToConvert()
2973 'DATE_INSERT' =>
'datetime',
2974 'DATE_UPDATE' =>
'datetime',
2975 'DATE_PAYED' =>
'datetime',
2976 'DATE_STATUS' =>
'datetime',
2977 'DATE_LOCK' =>
'datetime',
2978 'DATE_PAY_BEFORE' =>
'date',
2979 'DATE_BILL' =>
'date',
2980 'DATE_MARKED' =>
'datetime',
2981 'DATE_CANCELED' =>
'datetime',
2992 'DATE_ALLOW_DELIVERY',
2993 'EMP_ALLOW_DELIVERY_ID',
2996 'DELIVERY_DOC_DATE',
3002 'REASON_UNDO_DEDUCTED',
3031 'DATE_ALLOW_DELIVERY' =>
'datetime',
3032 'DELIVERY_DOC_DATE' =>
'date',
3033 'DATE_DEDUCTED' =>
'datetime',
3034 'DATE_MARKED' =>
'datetime',
3035 'DATE_RESPONSIBLE_ID' =>
'date',
3036 'DATE_INSERT' =>
'datetime',
3037 'TRACKING_LAST_CHECK' =>
'datetime',
3038 'TRACKING_LAST_CHANGE' =>
'datetime',
3044 'DATE_PAYED' =>
'datetime',
3045 'DATE_PAID' =>
'datetime',
3046 'PAY_VOUCHER_DATE' =>
'date',
3047 'PS_RESPONSE_DATE' =>
'datetime',
3058 'DATE_PAYED' =>
'datetime',
3059 'DATE_PAID' =>
'datetime',
3060 'PAY_VOUCHER_DATE' =>
'date',
3061 'PS_RESPONSE_DATE' =>
'datetime',
3073 'DATE_PAYED' =>
'DATE_PAID',
3074 'EMP_PAYED_ID' =>
'EMP_PAID_ID',
3101 $resetPrice =
false;
3102 $resetPriceDelivery =
false;
3107 if ($order->getId() == 0)
3109 $order->resetData(array(
'PRICE_DELIVERY'));
3110 $resetPriceDelivery =
true;
3115 if (!isset($basketData[
'ID']) || intval($basketData[
'ID']) <= 0)
3119 if (!$basketItem =
$basket->getItemById($basketData[
'ID']))
3122 if ($resetPriceDelivery ===
false)
3124 if (
$order->getId() == 0 || isset($basketData[
'PRICE'])
3125 && floatval($basketData[
'PRICE']) != $basketItem->getPrice())
3128 $order->resetData(array(
'PRICE'));
3144 if ($resetPriceDelivery && $resetPrice)
3163 "SITE_ID" =>
$order->getSiteId(),
3164 "LID" =>
$order->getSiteId(),
3165 "PERSON_TYPE_ID" =>
$order->getPersonTypeId(),
3166 "PRICE" =>
$order->getPrice(),
3167 "CURRENCY" =>
$order->getCurrency(),
3168 "USER_ID" =>
$order->getUserId(),
3169 "PAY_SYSTEM_ID" => (
int)
$order->getField(
'PAY_SYSTEM_ID'),
3170 "PRICE_DELIVERY" =>
$order->getDeliveryPrice(),
3171 "DELIVERY_ID" => (
int)
$order->getField(
'DELIVERY_ID'),
3172 "DISCOUNT_VALUE" =>
$order->getDiscountPrice(),
3173 "TAX_VALUE" =>
$order->getTaxValue(),
3174 "TRACKING_NUMBER" =>
$order->getField(
'TRACKING_NUMBER'),
3175 "PAYED" =>
$order->getField(
'PAYED'),
3176 "CANCELED" =>
$order->getField(
'CANCELED'),
3177 "STATUS_ID" =>
$order->getField(
'STATUS_ID'),
3178 "RESERVED" =>
$order->getField(
'RESERVED'),
3181 $orderFields = static::convertOrderToArray(
$order);
3182 if (is_array($orderFields))
3184 $orderFields =
$fields + $orderFields;
3185 $orderFields = static::convertDateFieldsToOldFormat($orderFields);
3190 'ORDER_FIELDS' => $orderFields,
3209 'ORDER_WEIGHT' => 0,
3210 'BASKET_ITEMS' => [],
3212 'DISCOUNT_LIST' => [],
3214 'VAT_RATE' =>
$order->getVatRate(),
3215 'VAT_SUM' =>
$order->getVatSum(),
3223 foreach (
$basket as $basketItem)
3226 $basketCompatibilityClassName = static::getBasketCompatibilityClassName();
3228 $fields[
'BASKET_ITEMS'][] = $basketCompatibilityClassName::convertBasketItemToArray($basketItem);
3235 if ($propertyCollection =
$order->getPropertyCollection())
3238 foreach ($propertyCollection as $property)
3241 $fields[
'ORDER_PROP'][$property->getPropertyId()] = $property->getValue();
3246 if ($propProfileName = $propertyCollection->getProfileName())
3247 $fields[
'PROFILE_NAME'] = $propProfileName->getValue();
3249 if ($propPayerName = $propertyCollection->getPayerName())
3250 $fields[
'PAYER_NAME'] = $propPayerName->getValue();
3252 if ($propUserEmail = $propertyCollection->getUserEmail())
3253 $fields[
'USER_EMAIL'] = $propUserEmail->getValue();
3255 if ($propDeliveryLocationZip = $propertyCollection->getDeliveryLocationZip())
3256 $fields[
'DELIVERY_LOCATION_ZIP'] = $propDeliveryLocationZip->getValue();
3258 if ($propDeliveryLocation = $propertyCollection->getDeliveryLocation())
3259 $fields[
'DELIVERY_LOCATION'] = $propDeliveryLocation->getValue();
3261 if ($propTaxLocation = $propertyCollection->getTaxLocation())
3262 $fields[
'TAX_LOCATION'] = $propTaxLocation->getValue();
3267 if ($tax =
$order->getTax())
3269 $fields[
'TAX_LIST'] = $tax->getTaxList();
3277 return ($this->externalPrice !==
null);
3288 $locationPropInfo = \CSaleOrder::getLocationPropertyInfo();
3290 static $propIndex = 0;
3293 if (mb_strpos($key,
"PROPERTY_ID_") === 0)
3302 $propIDTmp = intval(mb_substr($key, mb_strlen(
"PROPERTY_ID_")));
3304 $this->query->addFilter(
'='.$propRuntimeName.
'.ORDER_PROPS_ID', $propIDTmp);
3305 if(isset($locationPropInfo[
'ID'][$propIDTmp]))
3307 $this->
addQueryAlias(
'PROPERTY_ID_'.$propIDTmp,
'LOCATION.ID');
3311 $this->
addQueryAlias(
'PROPERTY_ID_'.$propIDTmp, $propRuntimeName.
'.ID');
3314 $output =
'PROPERTY_ID_'.$propIDTmp;
3317 elseif (mb_strpos($key,
"PROPERTY_ORDER_PROPS_ID_") === 0)
3326 $propIDTmp = intval(mb_substr($key, mb_strlen(
"PROPERTY_ORDER_PROPS_ID_")));
3328 $this->query->addFilter(
'='.$propRuntimeName.
'.ORDER_PROPS_ID', $propIDTmp);
3329 if(isset($locationPropInfo[
'ID'][$propIDTmp]))
3331 $this->
addQueryAlias(
'PROPERTY_ORDER_PROPS_ID_'.$propIDTmp,
'LOCATION.ID');
3335 $this->
addQueryAlias(
'PROPERTY_ORDER_PROPS_ID_'.$propIDTmp, $propRuntimeName.
'.ORDER_PROPS_ID');
3338 $output =
'PROPERTY_ORDER_PROPS_ID_'.$propIDTmp;
3340 elseif (mb_strpos($key,
"PROPERTY_NAME_") === 0)
3349 $propIDTmp = intval(mb_substr($key, mb_strlen(
"PROPERTY_NAME_")));
3351 $this->
addQueryAlias(
'PROPERTY_NAME_'.$propIDTmp, $propRuntimeName.
'.NAME');
3352 $this->query->addFilter(
'='.$propRuntimeName.
'.ORDER_PROPS_ID', $propIDTmp);
3354 $output =
'PROPERTY_NAME_'.$propIDTmp;
3356 elseif (mb_strpos($key,
"PROPERTY_VALUE_") === 0)
3365 $propIDTmp = intval(mb_substr($key, mb_strlen(
"PROPERTY_VALUE_")));
3367 if(isset($locationPropInfo[
'ID'][$propIDTmp]))
3369 $this->
addQueryAlias(
'PROPERTY_ID_'.$propIDTmp,
'LOCATION.ID');
3373 $this->
addQueryAlias(
'PROPERTY_ID_'.$propIDTmp, $propRuntimeName.
'.VALUE');
3376 $output =
'PROPERTY_ID_'.$propIDTmp;
3378 elseif (mb_strpos($key,
"PROPERTY_CODE_") === 0)
3387 $propIDTmp = intval(mb_substr($key, mb_strlen(
"PROPERTY_CODE_")));
3388 $this->
addQueryAlias(
'PROPERTY_CODE_'.$propIDTmp, $propRuntimeName.
'.CODE');
3389 $this->query->addFilter(
'='.$propRuntimeName.
'.ORDER_PROPS_ID', $propIDTmp);
3391 $output =
'PROPERTY_CODE_'.$propIDTmp;
3393 elseif (mb_strpos($key,
"PROPERTY_VAL_BY_CODE_") === 0)
3402 $propIDTmp = preg_replace(
"/[^a-zA-Z0-9_-]/is",
"", trim(mb_substr($key, mb_strlen(
"PROPERTY_VAL_BY_CODE_"))));
3404 $this->
addQueryAlias(
'PROPERTY_VAL_BY_CODE_'.$propIDTmp, $propRuntimeName.
'.VALUE');
3405 if(isset($locationPropInfo[
'CODE'][$propIDTmp]))
3407 $this->
addQueryAlias(
'PROPERTY_VAL_BY_CODE_'.$propIDTmp,
'LOCATION.ID');
3411 $this->
addQueryAlias(
'PROPERTY_VAL_BY_CODE_'.$propIDTmp, $propRuntimeName.
'.VALUE');
3414 $this->query->addFilter(
'='.$propRuntimeName.
'.CODE', $propIDTmp);
3416 $output =
'PROPERTY_VAL_BY_CODE_'.$propIDTmp;
3418 elseif (mb_strpos($key,
"BASKET_") === 0)
3420 $output = static::addBasketRuntime($key);
3423 if(isset($locationPropInfo[
'ID'][$propIDTmp]))
3425 $this->query->registerRuntimeField(
3428 'data_type' =>
'\Bitrix\Sale\Location\LocationTable',
3429 'reference' => array(
3430 '=this.PROPERTY.VALUE' =>
'ref.CODE'
3432 'join_type' =>
'inner'
3449 $this->query->registerRuntimeField(
3452 'data_type' =>
'\Bitrix\Sale\Internals\OrderPropsValueTable',
3453 'reference' => array(
3454 'ref.ORDER_ID' =>
'this.ID',
3456 'join_type' =>
'inner'
3460 $this->runtimeFields[] =
'PROPERTY_'.$index;
3461 $this->propertyRuntimeList[$index] =
'PROPERTY_'.$index;
3467 return (!empty($this->propertyRuntimeList[$index]) ? $this->propertyRuntimeList[$index] :
null);
3482 if ($key ==
"BASKET_DISCOUNT_COUPON")
3484 if (!in_array(
'COUPONS', $this->runtimeFields))
3486 $this->query->registerRuntimeField(
3489 'data_type' =>
'\Bitrix\Sale\Internals\OrderCouponsTable',
3490 'reference' => array(
3491 '=ref.ORDER_ID' =>
'this.ID'
3495 $this->runtimeFields[] =
"COUPONS";
3498 $this->
addQueryAlias(
'BASKET_DISCOUNT_COUPON',
'COUPONS.COUPON');
3499 $output =
'BASKET_DISCOUNT_COUPON';
3502 elseif ($key ==
"BASKET_DISCOUNT_NAME")
3504 if (!in_array(
'DISCOUNT_ORDER_RULES', $this->runtimeFields))
3506 $this->query->registerRuntimeField(
3507 'DISCOUNT_ORDER_RULES',
3509 'data_type' =>
'\Bitrix\Sale\Internals\OrderRulesTable',
3510 'reference' => array(
3511 '=ref.ORDER_ID' =>
'this.ID',
3515 $this->runtimeFields[] =
"DISCOUNT_ORDER_RULES";
3518 if (!in_array(
'DISCOUNT', $this->runtimeFields))
3520 $this->query->registerRuntimeField(
3523 'data_type' =>
'\Bitrix\Sale\Internals\OrderDiscountTable',
3524 'reference' => array(
3525 '=ref.ID' =>
'this.DISCOUNT_ORDER_RULES.ORDER_DISCOUNT_ID'
3530 $this->runtimeFields[] =
"DISCOUNT";
3533 $this->
addQueryAlias(
'BASKET_DISCOUNT_NAME',
'DISCOUNT.NAME');
3534 $output =
'BASKET_DISCOUNT_NAME';
3542 return Sale\Fuser::getId();