5use Bitrix\Main\DB\SqlExpression;
6use Bitrix\Main\Entity\ReferenceField;
7use Bitrix\Sale\Internals\CollectableEntity;
8use Bitrix\Sale\Internals\Entity;
9use Bitrix\Sale\Internals\OrderPropsRelationTable;
11use Bitrix\Sale\Internals\OrderPropsValueTable;
43 array $relation =
null
82 $propertyValuesMap = [];
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'],
145 while ($row =
$dbRes->fetch())
147 $properties[$row[
'ID']] = $row;
148 $propRelation[$row[
'ID']] = [];
151 if (!empty($properties))
153 $dbRes = OrderPropsRelationTable::getList(
161 'PROPERTY_ID' => array_keys($properties)
166 while ($row =
$dbRes->fetch())
168 $propRelation[$row[
'PROPERTY_ID']][] = $row;
172 return [$properties, $propertyValues, $propRelation, $propertyValuesMap];
188 '=ENTITY_TYPE' => static::getEntityType()
191 if ($entity->getPersonTypeId() > 0)
193 $filter[
'=PERSON_TYPE_ID'] = $entity->getPersonTypeId();
198 static::constructPropertyRelatedEntitiesFilter($entity)
201 if ($entity->getId() > 0)
203 $dbRes = static::getList([
204 'select' => [
'ORDER_PROPS_ID'],
206 '=ENTITY_ID' => $entity->getId(),
207 '=ENTITY_TYPE' => static::getEntityType()
211 while ($row =
$dbRes->fetch())
213 $subFilter[
'@ID'][] = $row[
'ORDER_PROPS_ID'];
224 $tpLandingList = static::extractTpLandingIdList($entity);
228 $dbRes = Internals\OrderPropsRelationTable::getList([
230 '@ENTITY_ID' => $tpLandingList,
231 '=ENTITY_TYPE' => OrderPropsRelationTable::ENTITY_TYPE_LANDING,
233 'cache' => [
'ttl' => 86400],
237 return (
bool)
$dbRes->fetch();
245 $tpList = static::extractTradingPlatformIdList($entity);
249 $dbRes = Internals\OrderPropsRelationTable::getList([
251 '@ENTITY_ID' => $tpList,
252 '=ENTITY_TYPE' => OrderPropsRelationTable::ENTITY_TYPE_TRADING_PLATFORM
254 'cache' => [
'ttl' => 86400],
258 return (
bool)
$dbRes->fetch();
272 $psFilter = [
'=RELATION_PS.ENTITY_ID' =>
null];
274 if ($paySystemList = static::extractPaySystemIdList($entity))
276 $psFilter[
'LOGIC'] =
'OR';
277 $psFilter[
'@RELATION_PS.ENTITY_ID'] = $paySystemList;
280 $result[] = $psFilter;
281 $dlvFilter = [
'=RELATION_DLV.ENTITY_ID' =>
null];
283 if ($deliveryList = static::extractDeliveryIdList($entity))
285 $dlvFilter[
'LOGIC'] =
'OR';
286 $dlvFilter[
'@RELATION_DLV.ENTITY_ID'] = $deliveryList;
289 $result[] = $dlvFilter;
291 if (self::hasPresetForLanding($entity))
295 '!RELATION_PS.ENTITY_ID' =>
null,
296 '!RELATION_DLV.ENTITY_ID' =>
null,
301 '@RELATION_TP_LANDING.ENTITY_ID' => static::extractTpLandingIdList($entity),
308 '=RELATION_TP_LANDING.ENTITY_ID' =>
null,
313 if (self::hasPresetFotTradingPlatform($entity))
317 '!RELATION_PS.ENTITY_ID' =>
null,
318 '!RELATION_DLV.ENTITY_ID' =>
null,
319 '!RELATION_TP_LANDING.ENTITY_ID' =>
null,
324 '@RELATION_TP.ENTITY_ID' => static::extractTradingPlatformIdList($entity),
331 '=RELATION_TP.ENTITY_ID' =>
null,
344 '\Bitrix\Sale\Internals\OrderPropsRelation',
346 '=this.ID' =>
'ref.PROPERTY_ID',
347 'ref.ENTITY_TYPE' =>
new SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_PAY_SYSTEM)
353 '\Bitrix\Sale\Internals\OrderPropsRelation',
355 '=this.ID' =>
'ref.PROPERTY_ID',
356 'ref.ENTITY_TYPE' =>
new SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_DELIVERY)
360 new Main\Entity\ReferenceField(
361 'RELATION_TP_LANDING',
362 '\Bitrix\Sale\Internals\OrderPropsRelation',
364 '=this.ID' =>
'ref.PROPERTY_ID',
365 'ref.ENTITY_TYPE' =>
new Main\
DB\
SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_LANDING)
369 new Main\Entity\ReferenceField(
371 '\Bitrix\Sale\Internals\OrderPropsRelation',
373 '=this.ID' =>
'ref.PROPERTY_ID',
374 'ref.ENTITY_TYPE' =>
new Main\
DB\
SqlExpression(
'?', OrderPropsRelationTable::ENTITY_TYPE_TRADING_PLATFORM)
392 array $propertyValues,
402 if (isset($propertyValuesMap[$id]))
404 $fields = $propertyValues[$propertyValuesMap[$id]];
405 unset($propertyValues[$propertyValuesMap[$id]]);
406 unset($propertyValuesMap[$id]);
418 $result[$id] = static::createPropertyValueObject(
$property, $fields, $propRelation[$id]);
434 return OrderPropsValueTable::getMap();
463 'PROPS_GROUP_ID' => 0,
464 'NAME' => $value[
'NAME'],
465 'CODE' => $value[
'CODE'],
467 'PERSON_TYPE_ID' =>
null,
468 'DESCRIPTION' =>
null,
470 'DEFAULT_VALUE' =>
null,
472 'USER_PROPS' =>
null,
473 'IS_LOCATION' =>
'N',
475 'IS_PROFILE_NAME' =>
'N',
477 'IS_LOCATION4TAX' =>
'N',
478 'IS_FILTERED' =>
'N',
482 'IS_ADDRESS_FROM' =>
'N',
483 'IS_ADDRESS_TO' =>
'N',
486 'INPUT_FIELD_LOCATION' =>
null,
491 $property[
'ENTITY_TYPE'] = static::getEntityType();
493 $propertyClassName = static::getPropertyClassName();
495 $this->
property =
new $propertyClassName(
$property, $relation);
497 if (isset($value[
'VALUE']))
499 $value[
'VALUE'] = $this->
property->normalizeValue($value[
'VALUE']);
502 parent::__construct($value);
507 'ORDER_PROPS_ID' => $this->
property->getId(),
508 'NAME' => $this->
property->getName(),
509 'CODE' => $this->
property->getField(
'CODE'),
510 'XML_ID' => static::generateXmlId(),
511 'ENTITY_TYPE' => $this->
property->getField(
'ENTITY_TYPE')
514 if (!empty($this->property->getField(
'DEFAULT_VALUE')))
516 $value[
'VALUE'] = $this->
property->getField(
'DEFAULT_VALUE');
519 $this->setFieldsNoDemand($value);
528 return uniqid(
'bx_');
572 if (
$name ===
'VALUE')
574 $value = $this->
property->normalizeValue($value);
577 return parent::normalizeValue(
$name, $value);
589 $this->checkCallingContext();
593 if (!$this->isChanged())
598 if ($this->getId() > 0)
607 if (!
$res->isSuccess())
609 $result->addErrors(
$res->getErrors());
617 private function checkCallingContext(): void
619 $order = $this->getOrder();
621 if (!
$order->isSaveRunning())
623 trigger_error(
"Incorrect call to the save process. Use method save() on \Bitrix\Sale\Order entity", E_USER_WARNING);
630 public function getOrder(): ?Order
657 $value = $this->
property->getPreparedValueForSave($this);
660 if (
$res->isSuccess())
662 $result->setId(
$res->getId());
666 $result->addErrors(
$res->getErrors());
677 protected function add()
681 $value = $this->
property->getPreparedValueForSave($this);
686 'ORDER_ID' => $this->getOrder()->getId(),
687 'ORDER_PROPS_ID' => $this->property->getId(),
688 'NAME' => $this->property->getName(),
690 'CODE' => $this->property->getField(
'CODE'),
691 'XML_ID' => $this->getField(
'XML_ID'),
692 'ENTITY_ID' => $this->getCollection()->getEntityParentId(),
693 'ENTITY_TYPE' => $this->getField(
'ENTITY_TYPE')
697 if (
$res->isSuccess())
699 $this->setFieldNoDemand(
'ID',
$res->getId());
717 static::getOnSavedEventName(),
720 'VALUES' => $this->fields->getOriginalValues(),
737 $key = ($this->getField(
'ORDER_PROPS_ID')) ?:
"n".$this->getInternalIndex();
739 if (is_array(
$post[
'PROPERTIES']) && array_key_exists(
$key,
$post[
'PROPERTIES']))
757 $res = $this->
property->checkValue($value);
758 if (!
$res->isSuccess())
782 $res = $this->
property->checkRequiredValue($value);
783 if (!
$res->isSuccess())
801 return $this->
property->getFields();
817 return $this->getField(
'ID');
825 return $this->
property->getId();
833 return $this->
property->getPersonTypeId();
841 return $this->
property->getGroupId();
849 return $this->
property->getName();
857 return $this->
property->getRelations();
865 return $this->
property->getDescription();
873 return $this->
property->getType();
881 return $this->
property->isRequired();
889 return $this->
property->isUtil();
915 return OrderPropsValueTable::add(
$data);
926 return OrderPropsValueTable::update($primary,
$data);
938 return OrderPropsValueTable::getList($parameters);
948 return $this->setField(
'VALUE', $value);
957 return $this->
property->getViewHtml($this->
getValue());
966 return $this->
property->getEditHtml($this->getFieldValues());
974 return $this->getField(
"VALUE");
981 public function verify()
984 if (!
$res->isSuccess())
986 $order = $this->getOrder();
991 $entityMarker = $registry->getEntityMarkerClassName();
992 $entityMarker::addMarker(
$order, $this,
$res);
1004 [$properties, $propertyValues, $propRelation, $propertyValuesMap] = static::loadFromDb($entity);
1005 return static::createPropertyValuesObjects($properties, $propertyValues, $propRelation, $propertyValuesMap);
1010 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
</td ></tr ></table ></td ></tr ><?endif?><? $propertyIndex=0;foreach( $arGlobalProperties as $propertyCode=> $propertyValue
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(empty($signedUserToken)) $key