39 return static::getList(
42 '=ENTITY_TYPE' => static::getEntityType(),
45 "select" => [
'ID',
'ORDER_PROPS_ID']
52 return $this->getEntityParent()->getId();
59 public function getItemByOrderPropertyId($orderPropertyId)
64 if (
$propertyValue->getField(
'ORDER_PROPS_ID') == $orderPropertyId)
80 public function getArray(
bool $refreshData =
false)
82 $groups = $this->getGroups($refreshData);
99 $p[
"ID"] =
"n".$propertyValue->getInternalIndex();
107 $value = array_values(Manager::asMultiple(
$p, $value));
114 return [
'groups' =>
$groups,
'properties' => $properties];
125 $r = static::deleteInternal($value[
'ID']);
131 $propertyClass = static::getPropertyClassName();
133 $property = $propertyClass::getObjectById($value[
'ORDER_PROPS_ID']);
134 if ($property && isset($value[
'VALUE']))
136 $property->onValueDelete($value[
'VALUE']);
141 $result->addErrors($r->getErrors());
155 public function createItem(
array $prop)
158 $propertyValueClass = static::getPropertyValueClassName();
159 $property = $propertyValueClass::create($this, $prop);
160 $this->addItem($property);
169 public function getAttribute(
$name)
171 $selectedEntityPropertyValueList = [];
174 foreach ($this->collection as $item)
176 $property = $item->getPropertyObject();
177 if ($property->getField(
$name) ===
'Y')
179 $selectedEntityPropertyValueList[] = $item;
183 if (
count($selectedEntityPropertyValueList) > 1)
185 foreach ($selectedEntityPropertyValueList as $item)
187 if (!empty($item->getValue()))
194 return $selectedEntityPropertyValueList[0] ??
null;
203 return $this->getAttribute(
'IS_EMAIL');
212 return $this->getAttribute(
'IS_PAYER');
220 return $this->getAttribute(
'IS_LOCATION');
228 return $this->getAttribute(
'IS_LOCATION4TAX');
236 return $this->getAttribute(
'IS_PROFILE_NAME');
244 return $this->getAttribute(
'IS_ZIP');
252 return $this->getAttribute(
'IS_PHONE');
260 return $this->getAttribute(
'IS_ADDRESS');
268 return $this->getAttribute(
'IS_ADDRESS_FROM');
276 return $this->getAttribute(
'IS_ADDRESS_TO');
283 public function getGroups(
bool $refreshData =
false)
291 $group = $property->getGroupInfo($refreshData);
292 if (!isset(
$result[$group[
'ID']]))
294 $result[$group[
'ID']] = $group;
305 public function getPropertiesByGroupId($groupId)
320 $propertyGroupId = (int)$property->getGroupId();
321 if (!isset(
$groups[$propertyGroupId]))
323 $propertyGroupId = 0;
326 if ($propertyGroupId === (
int)$groupId)
360 public function verify()
368 if (!$r->isSuccess())
370 $result->addErrors($r->getErrors());
380 public function save()
389 $itemsFromDb = $this->getOriginalItemsValues();
390 foreach ($itemsFromDb as
$k => $v)
392 if ($this->getItemById(
$k))
399 $r = static::delete($v);
400 if (!$r->isSuccess())
402 $result->addErrors($r->getErrors());
409 foreach ($this->collection as $property)
411 $r = $property->save();
412 if (!$r->isSuccess())
414 $result->addErrors($r->getErrors());
426 protected function getOriginalItemsValues()
429 if (!
$entity = $this->getEntityParent())
431 throw new ObjectNotFoundException(
'Entity not found');
437 $itemsFromDbList = static::getList(
440 "=ENTITY_ID" =>
$entity->getId(),
441 "=ENTITY_TYPE" => static::getEntityType()
444 "ID",
"NAME",
"CODE",
"VALUE",
"ORDER_PROPS_ID",
"ENTITY_ID",
"ENTITY_TYPE"
449 while ($itemsFromDbItem = $itemsFromDbList->fetch())
451 $itemsFromDb[$itemsFromDbItem[
"ID"]] = $itemsFromDbItem;
463 $values[
'ENTITY_REGISTRY_TYPE'] = static::getRegistryType();
467 static::getOnValueDeletedEventName(),
468 [
'VALUES' => $values]
480 return $this->getItemsByFilter(
505 $values[
'ENTITY_REGISTRY_TYPE'] = static::getRegistryType();
509 static::getOnBeforeValueDeletedEventName(),
510 [
'VALUES' => $values]
521 return OrderPropsValueTable::delete($primary);
530 return OrderPropsValueTable::getList($parameters);
536 public function refreshRelated(): void
539 $propertyValueClassName = static::getPropertyValueClassName();
540 $props = $propertyValueClassName::loadForEntity($this->getEntityParent());
561 if (!$this->getItemByOrderPropertyId(
$propertyValue->getPropertyId()))
581 foreach ($this->collection as $property)
583 $r = $property->setValueFromPost(
$post);
584 if (!$r->isSuccess())
586 $result->addErrors($r->getErrors());
599 public function checkErrors(
$fields,
$files, $skipUtils =
false)
619 $key =
"n".$propertyValue->getInternalIndex();
630 if (!$r->isSuccess())
632 $result->addErrors($r->getErrors());
658 $key =
"n".$propertyValue->getInternalIndex();
661 if (!in_array(
$key, $rules))
673 if (!$r->isSuccess())
675 $result->addErrors($r->getErrors());
691 $propertiesDataList = static::getAllItemsFromDb(
$entityId);
697 if (!
$res->isSuccess())