43 array $relation =
null
79 protected static function loadFromDb(
Entity $entity): array
82 $propertyValuesMap = [];
84 if ($entity->getId() > 0)
86 $dbRes = static::getList(
88 'select' => [
'ID',
'NAME',
'VALUE',
'CODE',
'ORDER_PROPS_ID'],
90 '=ENTITY_ID' => $entity->getId(),
91 '=ENTITY_TYPE' => static::getEntityType()
95 while ($row = $dbRes->fetch())
97 $propertyValues[$row[
'ID']] = $row;
98 $propertyValuesMap[$row[
'ORDER_PROPS_ID']] = $row[
'ID'];
103 $propertyClassName = static::getPropertyClassName();
131 'INPUT_FIELD_LOCATION',
136 'filter' => static::constructPropertyFilter($entity),
137 'runtime' => static::getRelationRuntimeFields(),
138 'order' => [
'SORT' =>
'ASC'],
141 $dbRes = $propertyClassName::getList($getListParams);
145 while ($row = $dbRes->fetch())
147 $properties[$row[
'ID']] = $row;
148 $propRelation[$row[
'ID']] = [];
151 $dbRes = OrderPropsRelationTable::getList(
159 'PROPERTY_ID' => array_keys($properties)
164 while ($row = $dbRes->fetch())
166 $propRelation[$row[
'PROPERTY_ID']][] = $row;
169 return [$properties, $propertyValues, $propRelation, $propertyValuesMap];
185 '=ENTITY_TYPE' => static::getEntityType()
188 if ($entity->getPersonTypeId() > 0)
190 $filter[
'=PERSON_TYPE_ID'] = $entity->getPersonTypeId();
195 static::constructPropertyRelatedEntitiesFilter($entity)
198 if ($entity->getId() > 0)
200 $dbRes = static::getList([
201 'select' => [
'ORDER_PROPS_ID'],
203 '=ENTITY_ID' => $entity->getId(),
204 '=ENTITY_TYPE' => static::getEntityType()
208 while ($row = $dbRes->fetch())
210 $subFilter[
'@ID'][] = $row[
'ORDER_PROPS_ID'];
214 $filter[] = $subFilter;
221 $tpLandingList = static::extractTpLandingIdList($entity);
225 $dbRes = Internals\OrderPropsRelationTable::getList([
227 '@ENTITY_ID' => $tpLandingList,
228 '=ENTITY_TYPE' => OrderPropsRelationTable::ENTITY_TYPE_LANDING,
230 'cache' => [
'ttl' => 86400],
234 return (
bool)$dbRes->fetch();
242 $tpList = static::extractTradingPlatformIdList($entity);
246 $dbRes = Internals\OrderPropsRelationTable::getList([
248 '@ENTITY_ID' => $tpList,
249 '=ENTITY_TYPE' => OrderPropsRelationTable::ENTITY_TYPE_TRADING_PLATFORM
251 'cache' => [
'ttl' => 86400],
255 return (
bool)$dbRes->fetch();
269 $psFilter = [
'=RELATION_PS.ENTITY_ID' =>
null];
271 if ($paySystemList = static::extractPaySystemIdList($entity))
273 $psFilter[
'LOGIC'] =
'OR';
274 $psFilter[
'@RELATION_PS.ENTITY_ID'] = $paySystemList;
277 $result[] = $psFilter;
278 $dlvFilter = [
'=RELATION_DLV.ENTITY_ID' =>
null];
280 if ($deliveryList = static::extractDeliveryIdList($entity))
282 $dlvFilter[
'LOGIC'] =
'OR';
283 $dlvFilter[
'@RELATION_DLV.ENTITY_ID'] = $deliveryList;
286 $result[] = $dlvFilter;
288 if (self::hasPresetForLanding($entity))
292 '!RELATION_PS.ENTITY_ID' =>
null,
293 '!RELATION_DLV.ENTITY_ID' =>
null,
298 '@RELATION_TP_LANDING.ENTITY_ID' => static::extractTpLandingIdList($entity),
305 '=RELATION_TP_LANDING.ENTITY_ID' =>
null,
310 if (self::hasPresetFotTradingPlatform($entity))
314 '!RELATION_PS.ENTITY_ID' =>
null,
315 '!RELATION_DLV.ENTITY_ID' =>
null,
316 '!RELATION_TP_LANDING.ENTITY_ID' =>
null,
321 '@RELATION_TP.ENTITY_ID' => static::extractTradingPlatformIdList($entity),
328 '=RELATION_TP.ENTITY_ID' =>
null,
341 '\Bitrix\Sale\Internals\OrderPropsRelation',
343 '=this.ID' =>
'ref.PROPERTY_ID',
344 'ref.ENTITY_TYPE' =>
new SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_PAY_SYSTEM)
350 '\Bitrix\Sale\Internals\OrderPropsRelation',
352 '=this.ID' =>
'ref.PROPERTY_ID',
353 'ref.ENTITY_TYPE' =>
new SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_DELIVERY)
357 new Main\Entity\ReferenceField(
358 'RELATION_TP_LANDING',
359 '\Bitrix\Sale\Internals\OrderPropsRelation',
361 '=this.ID' =>
'ref.PROPERTY_ID',
362 'ref.ENTITY_TYPE' =>
new Main\DB\
SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_LANDING)
366 new Main\Entity\ReferenceField(
368 '\Bitrix\Sale\Internals\OrderPropsRelation',
370 '=this.ID' =>
'ref.PROPERTY_ID',
371 'ref.ENTITY_TYPE' =>
new Main\DB\
SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_TRADING_PLATFORM)
389 array $propertyValues,
391 array $propertyValuesMap): array
399 if (isset($propertyValuesMap[$id]))
401 $fields = $propertyValues[$propertyValuesMap[$id]];
402 unset($propertyValues[$propertyValuesMap[$id]]);
403 unset($propertyValuesMap[$id]);
415 $result[$id] = static::createPropertyValueObject(
$property, $fields, $propRelation[$id]);
418 foreach ($propertyValues as $propertyValue)
420 $result[$propertyValue[
'ORDER_PROPS_ID']] = static::createPropertyValueObject(
null, $propertyValue);
431 return OrderPropsValueTable::getMap();
460 'PROPS_GROUP_ID' => 0,
461 'NAME' => $value[
'NAME'],
462 'CODE' => $value[
'CODE'],
464 'PERSON_TYPE_ID' =>
null,
465 'DESCRIPTION' =>
null,
467 'DEFAULT_VALUE' =>
null,
469 'USER_PROPS' =>
null,
470 'IS_LOCATION' =>
'N',
472 'IS_PROFILE_NAME' =>
'N',
474 'IS_LOCATION4TAX' =>
'N',
475 'IS_FILTERED' =>
'N',
479 'IS_ADDRESS_FROM' =>
'N',
480 'IS_ADDRESS_TO' =>
'N',
483 'INPUT_FIELD_LOCATION' =>
null,
488 $property[
'ENTITY_TYPE'] = static::getEntityType();
490 $propertyClassName = static::getPropertyClassName();
492 $this->
property =
new $propertyClassName(
$property, $relation);
494 if (isset($value[
'VALUE']))
496 $value[
'VALUE'] = $this->
property->normalizeValue($value[
'VALUE']);
499 parent::__construct($value);
504 'ORDER_PROPS_ID' => $this->
property->getId(),
505 'NAME' => $this->
property->getName(),
506 'CODE' => $this->
property->getField(
'CODE'),
507 'XML_ID' => static::generateXmlId(),
508 'ENTITY_TYPE' => $this->
property->getField(
'ENTITY_TYPE')
511 if (!empty($this->property->getField(
'DEFAULT_VALUE')))
513 $value[
'VALUE'] = $this->
property->getField(
'DEFAULT_VALUE');
516 $this->setFieldsNoDemand($value);
525 return uniqid(
'bx_');
537 $propertyValue = static::createPropertyValueObject(
$property);
539 return $propertyValue;
569 if ($name ===
'VALUE')
571 $value = $this->
property->normalizeValue($value);
574 return parent::normalizeValue($name, $value);
586 $this->checkCallingContext();
590 if (!$this->isChanged())
595 if ($this->getId() > 0)
604 if (!$res->isSuccess())
606 $result->addErrors($res->getErrors());
614 private function checkCallingContext(): void
616 $order = $this->getOrder();
618 if (!$order->isSaveRunning())
620 trigger_error(
"Incorrect call to the save process. Use method save() on \Bitrix\Sale\Order entity", E_USER_WARNING);
627 public function getOrder(): ?Order
654 $value = $this->
property->getPreparedValueForSave($this);
655 $res = $this->
updateInternal($this->getId(), [
'VALUE' => $value]);
657 if ($res->isSuccess())
659 $result->setId($res->getId());
663 $result->addErrors($res->getErrors());
674 protected function add()
678 $value = $this->
property->getPreparedValueForSave($this);
683 'ORDER_ID' => $this->getOrder()->getId(),
684 'ORDER_PROPS_ID' => $this->property->getId(),
685 'NAME' => $this->property->getName(),
687 'CODE' => $this->property->getField(
'CODE'),
688 'XML_ID' => $this->getField(
'XML_ID'),
689 'ENTITY_ID' => $this->getCollection()->getEntityParentId(),
690 'ENTITY_TYPE' => $this->getField(
'ENTITY_TYPE')
694 if ($res->isSuccess())
696 $this->setFieldNoDemand(
'ID', $res->getId());
697 $result->setId($res->getId());
701 $result->addErrors($res->getErrors());
714 static::getOnSavedEventName(),
717 'VALUES' => $this->fields->getOriginalValues(),
734 $key = ($this->getField(
'ORDER_PROPS_ID')) ?:
"n".$this->getInternalIndex();
736 if (is_array($post[
'PROPERTIES']) && array_key_exists($key, $post[
'PROPERTIES']))
738 $this->
setValue($post[
'PROPERTIES'][$key]);
754 $res = $this->
property->checkValue($value);
755 if (!$res->isSuccess())
757 $errors = $res->getErrors();
758 foreach ($errors as $error)
760 $result->addError(
new ResultError($error->getMessage(),
"PROPERTIES[$key]"));
761 $result->addError(
new ResultWarning($error->getMessage(),
"PROPERTIES[$key]"));
779 $res = $this->
property->checkRequiredValue($value);
780 if (!$res->isSuccess())
782 $errors = $res->getErrors();
783 foreach ($errors as $error)
785 $result->addError(
new ResultError($error->getMessage(),
"PROPERTIES[$key]"));
786 $result->addError(
new ResultWarning($error->getMessage(),
"PROPERTIES[$key]"));
798 return $this->
property->getFields();
814 return $this->getField(
'ID');
822 return $this->
property->getId();
830 return $this->
property->getPersonTypeId();
838 return $this->
property->getGroupId();
846 return $this->
property->getName();
854 return $this->
property->getRelations();
862 return $this->
property->getDescription();
870 return $this->
property->getType();
878 return $this->
property->isRequired();
886 return $this->
property->isUtil();
912 return OrderPropsValueTable::add($data);
923 return OrderPropsValueTable::update($primary, $data);
933 public static function getList(array $parameters = [])
935 return OrderPropsValueTable::getList($parameters);
945 return $this->setField(
'VALUE', $value);
954 return $this->
property->getViewHtml($this->
getValue());
963 return $this->
property->getEditHtml($this->getFieldValues());
971 return $this->getField(
"VALUE");
978 public function verify()
981 if (!$res->isSuccess())
983 $order = $this->getOrder();
988 $entityMarker = $registry->getEntityMarkerClassName();
989 $entityMarker::addMarker($order, $this, $res);
1001 [$properties, $propertyValues, $propRelation, $propertyValuesMap] = static::loadFromDb($entity);
1002 return static::createPropertyValuesObjects($properties, $propertyValues, $propRelation, $propertyValuesMap);
1007 return \Bitrix\Sale\Internals\OrderPropsValueTable::getEntity();