6use Bitrix\Main\Entity\ReferenceField;
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,
233 return (
bool)$dbRes->fetch();
241 $tpList = static::extractTradingPlatformIdList($entity);
245 $dbRes = Internals\OrderPropsRelationTable::getList([
247 '@ENTITY_ID' => $tpList,
248 '=ENTITY_TYPE' => OrderPropsRelationTable::ENTITY_TYPE_TRADING_PLATFORM
253 return (
bool)$dbRes->fetch();
267 $psFilter = [
'=RELATION_PS.ENTITY_ID' =>
null];
269 if ($paySystemList = static::extractPaySystemIdList($entity))
271 $psFilter[
'LOGIC'] =
'OR';
272 $psFilter[
'@RELATION_PS.ENTITY_ID'] = $paySystemList;
275 $result[] = $psFilter;
276 $dlvFilter = [
'=RELATION_DLV.ENTITY_ID' =>
null];
278 if ($deliveryList = static::extractDeliveryIdList($entity))
280 $dlvFilter[
'LOGIC'] =
'OR';
281 $dlvFilter[
'@RELATION_DLV.ENTITY_ID'] = $deliveryList;
284 $result[] = $dlvFilter;
286 if (self::hasPresetForLanding($entity))
290 '!RELATION_PS.ENTITY_ID' =>
null,
291 '!RELATION_DLV.ENTITY_ID' =>
null,
296 '@RELATION_TP_LANDING.ENTITY_ID' => static::extractTpLandingIdList($entity),
303 '=RELATION_TP_LANDING.ENTITY_ID' =>
null,
308 if (self::hasPresetFotTradingPlatform($entity))
312 '!RELATION_PS.ENTITY_ID' =>
null,
313 '!RELATION_DLV.ENTITY_ID' =>
null,
314 '!RELATION_TP_LANDING.ENTITY_ID' =>
null,
319 '@RELATION_TP.ENTITY_ID' => static::extractTradingPlatformIdList($entity),
326 '=RELATION_TP.ENTITY_ID' =>
null,
339 '\Bitrix\Sale\Internals\OrderPropsRelation',
341 '=this.ID' =>
'ref.PROPERTY_ID',
342 'ref.ENTITY_TYPE' =>
new SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_PAY_SYSTEM)
348 '\Bitrix\Sale\Internals\OrderPropsRelation',
350 '=this.ID' =>
'ref.PROPERTY_ID',
351 'ref.ENTITY_TYPE' =>
new SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_DELIVERY)
355 new Main\Entity\ReferenceField(
356 'RELATION_TP_LANDING',
357 '\Bitrix\Sale\Internals\OrderPropsRelation',
359 '=this.ID' =>
'ref.PROPERTY_ID',
360 'ref.ENTITY_TYPE' =>
new Main\DB\
SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_LANDING)
364 new Main\Entity\ReferenceField(
366 '\Bitrix\Sale\Internals\OrderPropsRelation',
368 '=this.ID' =>
'ref.PROPERTY_ID',
369 'ref.ENTITY_TYPE' =>
new Main\DB\
SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_TRADING_PLATFORM)
387 array $propertyValues,
389 array $propertyValuesMap): array
397 if (isset($propertyValuesMap[$id]))
399 $fields = $propertyValues[$propertyValuesMap[$id]];
400 unset($propertyValues[$propertyValuesMap[$id]]);
401 unset($propertyValuesMap[$id]);
413 $result[$id] = static::createPropertyValueObject(
$property, $fields, $propRelation[$id]);
416 foreach ($propertyValues as $propertyValue)
418 $result[$propertyValue[
'ORDER_PROPS_ID']] = static::createPropertyValueObject(
null, $propertyValue);
429 return OrderPropsValueTable::getMap();
458 'PROPS_GROUP_ID' => 0,
459 'NAME' => $value[
'NAME'],
460 'CODE' => $value[
'CODE'],
462 'PERSON_TYPE_ID' =>
null,
463 'DESCRIPTION' =>
null,
465 'DEFAULT_VALUE' =>
null,
467 'USER_PROPS' =>
null,
468 'IS_LOCATION' =>
'N',
470 'IS_PROFILE_NAME' =>
'N',
472 'IS_LOCATION4TAX' =>
'N',
473 'IS_FILTERED' =>
'N',
477 'IS_ADDRESS_FROM' =>
'N',
478 'IS_ADDRESS_TO' =>
'N',
481 'INPUT_FIELD_LOCATION' =>
null,
486 $property[
'ENTITY_TYPE'] = static::getEntityType();
488 $propertyClassName = static::getPropertyClassName();
490 $this->
property =
new $propertyClassName(
$property, $relation);
492 if (isset($value[
'VALUE']))
494 $value[
'VALUE'] = $this->
property->normalizeValue($value[
'VALUE']);
497 parent::__construct($value);
502 'ORDER_PROPS_ID' => $this->
property->getId(),
503 'NAME' => $this->
property->getName(),
504 'CODE' => $this->
property->getField(
'CODE'),
505 'XML_ID' => static::generateXmlId(),
506 'ENTITY_TYPE' => $this->
property->getField(
'ENTITY_TYPE')
509 if (!empty($this->property->getField(
'DEFAULT_VALUE')))
511 $value[
'VALUE'] = $this->
property->getField(
'DEFAULT_VALUE');
514 $this->setFieldsNoDemand($value);
523 return uniqid(
'bx_');
535 $propertyValue = static::createPropertyValueObject(
$property);
537 return $propertyValue;
567 if ($name ===
'VALUE')
569 $value = $this->
property->normalizeValue($value);
572 return parent::normalizeValue($name, $value);
584 $this->checkCallingContext();
588 if (!$this->isChanged())
593 if ($this->getId() > 0)
602 if (!$res->isSuccess())
604 $result->addErrors($res->getErrors());
612 private function checkCallingContext(): void
614 $order = $this->getOrder();
616 if (!$order->isSaveRunning())
618 trigger_error(
"Incorrect call to the save process. Use method save() on \Bitrix\Sale\Order entity", E_USER_WARNING);
625 public function getOrder(): ?Order
652 $value = $this->
property->getPreparedValueForSave($this);
653 $res = $this->
updateInternal($this->getId(), [
'VALUE' => $value]);
655 if ($res->isSuccess())
657 $result->setId($res->getId());
661 $result->addErrors($res->getErrors());
672 protected function add()
676 $value = $this->
property->getPreparedValueForSave($this);
681 'ORDER_ID' => $this->getOrder()->getId(),
682 'ORDER_PROPS_ID' => $this->property->getId(),
683 'NAME' => $this->property->getName(),
685 'CODE' => $this->property->getField(
'CODE'),
686 'XML_ID' => $this->getField(
'XML_ID'),
687 'ENTITY_ID' => $this->getCollection()->getEntityParentId(),
688 'ENTITY_TYPE' => $this->getField(
'ENTITY_TYPE')
692 if ($res->isSuccess())
694 $this->setFieldNoDemand(
'ID', $res->getId());
695 $result->setId($res->getId());
699 $result->addErrors($res->getErrors());
712 static::getOnSavedEventName(),
715 'VALUES' => $this->fields->getOriginalValues(),
732 $key = ($this->getField(
'ORDER_PROPS_ID')) ?:
"n".$this->
getInternalIndex();
734 if (is_array($post[
'PROPERTIES']) && array_key_exists($key, $post[
'PROPERTIES']))
736 $this->
setValue($post[
'PROPERTIES'][$key]);
752 $res = $this->
property->checkValue($value);
753 if (!$res->isSuccess())
755 $errors = $res->getErrors();
756 foreach ($errors as $error)
758 $result->addError(
new ResultError($error->getMessage(),
"PROPERTIES[$key]"));
759 $result->addError(
new ResultWarning($error->getMessage(),
"PROPERTIES[$key]"));
777 $res = $this->
property->checkRequiredValue($value);
778 if (!$res->isSuccess())
780 $errors = $res->getErrors();
781 foreach ($errors as $error)
783 $result->addError(
new ResultError($error->getMessage(),
"PROPERTIES[$key]"));
784 $result->addError(
new ResultWarning($error->getMessage(),
"PROPERTIES[$key]"));
796 return $this->
property->getFields();
812 return $this->getField(
'ID');
820 return $this->
property->getId();
828 return $this->
property->getPersonTypeId();
836 return $this->
property->getGroupId();
844 return $this->
property->getName();
852 return $this->
property->getRelations();
860 return $this->
property->getDescription();
868 return $this->
property->getType();
876 return $this->
property->isRequired();
884 return $this->
property->isUtil();
910 return OrderPropsValueTable::add($data);
921 return OrderPropsValueTable::update($primary, $data);
931 public static function getList(array $parameters = [])
933 return OrderPropsValueTable::getList($parameters);
943 return $this->setField(
'VALUE', $value);
952 return $this->
property->getViewHtml($this->
getValue());
961 return $this->
property->getEditHtml($this->getFieldValues());
969 return $this->getField(
"VALUE");
976 public function verify()
979 if (!$res->isSuccess())
981 $order = $this->getOrder();
986 $entityMarker = $registry->getEntityMarkerClassName();
987 $entityMarker::addMarker($order, $this, $res);
999 [$properties, $propertyValues, $propRelation, $propertyValuesMap] = static::loadFromDb($entity);
1000 return static::createPropertyValuesObjects($properties, $propertyValues, $propRelation, $propertyValuesMap);
1005 return \Bitrix\Sale\Internals\OrderPropsValueTable::getEntity();
static constructPropertyFilter(Entity $entity)
static getRegistryEntity()
updateInternal($primary, array $data)
checkRequiredValue($key, $value)
setValueFromPost(array $post)
static extractPaySystemIdList(Entity $entity)
static create(EntityPropertyValueCollection $collection, array $property=[])
static getOnSavedEventName()
static getMeaningfulFields()
static extractTpLandingIdList(Entity $entity)
static extractDeliveryIdList(Entity $entity)
static loadForEntity(Entity $entity)
static getAvailableFields()
static hasPresetFotTradingPlatform(Entity $entity)
static constructPropertyRelatedEntitiesFilter(Entity $entity)
callEventOnPropertyValueEntitySaved()
static createPropertyValueObject(array $property=null, array $value=[], array $relation=null)
__construct(array $property=null, array $value=[], array $relation=null)
static hasPresetForLanding(Entity $entity)
normalizeValue($name, $value)
static createPropertyValuesObjects(array $properties, array $propertyValues, array $propRelation, array $propertyValuesMap)
static getList(array $parameters=[])
static getRelationRuntimeFields()
static getPropertyClassName()
static extractTradingPlatformIdList(Entity $entity)
const ENTITY_PROPERTY_VALUE
static getInstance($type)
const REGISTRY_TYPE_ORDER