9use Bitrix\Main\Entity\ExpressionField;
21Loc::loadMessages($_SERVER[
"DOCUMENT_ROOT"].
'/bitrix/modules/sale/admin/order_props_edit.php');
38 if(!in_array($type, array_keys($this->
getTypes()[
'ENUM'])))
40 $r->addError(
new Error(
'type is out of range', 200850000008));
50 $entity = new \Bitrix\Sale\Rest\Entity\Property();
51 return [
'PROPERTY'=>$entity->prepareFieldInfos(
52 $entity->getFieldsByType($type)
62 $fillFields = $this->
get($id);
63 $fields[
'ID'] = $fillFields[
'ID'];
64 $fields[
'TYPE'] = $fillFields[
'TYPE'];
65 $fields[
'PROPS_GROUP_ID'] = $fillFields[
'PROPS_GROUP_ID'];
66 $fields[
'PERSON_TYPE_ID'] = $fillFields[
'PERSON_TYPE_ID'];
68 if(isset($fields[
'SETTINGS']))
70 $fields = array_merge($fields, $fields[
'SETTINGS']);
71 unset($fields[
'SETTINGS']);
78 $this->personTypeId = $fields[
'PERSON_TYPE_ID'];
79 $this->
property = $fields;
87 foreach ($this->errors as $error)
89 $r->addError(
new Error($error, 200850000003));
101 return [
'PROPERTY'=>$this->
get($this->
property[
'ID'])];
110 return [
'PROPERTY'=>$this->
get($id)];
121 $orderProps = new \CSaleOrderProps();
126 if (!$orderProps->Delete($id))
128 if ($ex = self::getApplication()->GetException())
129 $r->addError(
new Error($ex->GetString(), $ex->GetId()));
131 $r->addError(
new Error(
'delete property error', 200850000004));
146 public function listAction(
PageNavigation $pageNavigation, $select=[], $filter=[], $order=[]):
Page
148 $select = empty($select) ? [
'*'] : $select;
149 $order = empty($order) ? [
'ID' =>
'ASC'] : $order;
152 $propertyClassName = $this->getPropertyClassName();
154 $items = $propertyClassName::getList(
159 'offset' => $pageNavigation->
getOffset(),
160 'limit' => $pageNavigation->
getLimit(),
164 return new Page(
'PROPERTIES', $items,
function() use ($filter)
167 $propertyClassName = $this->getPropertyClassName();
169 return (
int) $propertyClassName::getList([
184 return \Bitrix\Sale\Property::class;
192 return Registry::ENTITY_ORDER;
197 $fields = self::prepareFields($fields);
198 if (isset($fields[
'SETTINGS']) && is_array($fields[
'SETTINGS']))
200 $fields = array_merge($fields, $fields[
'SETTINGS']);
201 unset($fields[
'SETTINGS']);
206 if(!isset($fields[
'PERSON_TYPE_ID']) || trim($fields[
'PERSON_TYPE_ID'])==
'')
207 $r->addError(
new Error(
'person type id is empty', 200850000005));
211 $this->personTypeId = $fields[
'PERSON_TYPE_ID'];
213 $this->
property = $fields;
220 foreach ($this->errors as $error)
222 $r->addError(
new Error($error, 200850000006));
233 return [
'PROPERTY'=>$this->
get($this->
property[
'ID'])];
242 if(isset($fields[
'MULTIPLE']) && $fields[
'MULTIPLE'] ==
'Y')
244 if(isset($fields[
'IS_FILTERED']) ==
false)
246 $r->addError(
new Error(
'Require fields: isFiltered.' , 200850000009));
248 elseif($fields[
'IS_FILTERED'] <>
'N')
250 $r->addError(
new Error(
'Allowed values: isFiltered - [N]', 200850000010));
256 if(isset($fields[
'IS_LOCATION']) && $fields[
'IS_LOCATION'] ==
'Y')
258 if(isset($fields[
'MULTIPLE']) ==
false)
260 $r->addError(
new Error(
'Require fields: multiple.', 200850000011));
262 elseif ($fields[
'MULTIPLE'] <>
'N')
264 $r->addError(
new Error(
'Allowed values: multiple - [N]', 200850000012));
268 if(isset($fields[
'IS_LOCATION4TAX']) && $fields[
'IS_LOCATION4TAX'] ==
'Y')
270 if(isset($fields[
'MULTIPLE']) ==
false)
272 $r->addError(
new Error(
'Require fields: multiple.', 200850000013));
274 elseif ($fields[
'MULTIPLE'] <>
'N')
276 $r->addError(
new Error(
'Allowed values: multiple - [N]', 200850000014));
283 if(isset($fields[
'IS_PROFILE_NAME']) && $fields[
'IS_PROFILE_NAME'] ==
'Y')
285 if(isset($fields[
'REQUIRED']) ==
false)
287 $r->addError(
new Error(
'Require fields: require.', 200850000015));
289 elseif ($fields[
'REQUIRED'] <>
'Y')
291 $r->addError(
new Error(
'Allowed values: require - [Y]', 200850000016));
302 foreach(array_keys(Manager::getTypes()) as $type)
304 $fields = self::getCommonFields();
306 $fields += Manager::getCommonSettings([
'TYPE'=>$type],
null );
308 $fields[
'MULTIPLE'][
'DESCRIPTION'] =
Loc::getMessage(
'MULTIPLE_DESCRIPTION');
310 $fields[
'DEFAULT_VALUE']=[
318 if ($type ===
'STRING')
322 elseif ($type ===
'LOCATION')
326 elseif ($type ===
'ADDRESS')
331 foreach ($fields as $code=>&$v)
333 foreach ($v as $name=>$value)
335 if(in_array($name, [
'ONCHANGE',
'ONCLICK',
'OPTIONS']))
351 if($this->
get($id)[
'ID']<=0)
352 $r->addError(
new Error(
'property is not exists', 200840400001));
357 protected function get($id)
365 $orderPropsGroup = new \CSaleOrderPropsGroup();
367 $result = $orderPropsGroup->GetList([
'NAME' =>
'ASC'], [
'PERSON_TYPE_ID' => $this->personTypeId]);
368 while ($row = $result->Fetch())
370 $groupOptions[$row[
'ID']] = $row[
'NAME'];
373 return $groupOptions;
378 $personTypeList = \Bitrix\Sale\PersonType::load($this->siteId,
$personTypeId);
380 return isset($personTypeList[
$personTypeId]) ? $personTypeList[$personTypeId] :
null;
393 'PERSON_TYPE_ID' => [
401 'PROPS_GROUP_ID' => [
457 'PERSON_TYPE_ID' => [
464 'RLABEL' => $personType[
'NAME']
466 'PROPS_GROUP_ID' => [
469 'OPTIONS' => $groupOptions
521 if (!empty($this->property[
'ID']))
523 $commonSettings = array_merge(
531 'RLABEL' => $this->property[
'ID']
538 $commonSettings += Manager::getCommonSettings($this->property,
null );
540 if (!empty($commonSettings[
'TYPE'][
'OPTIONS']))
542 foreach ($commonSettings[
'TYPE'][
'OPTIONS'] as $key => $option)
544 $commonSettings[
'TYPE'][
'OPTIONS'][$key] = mb_substr($option, 0, mb_strpos($option,
'[') - 1);
555 $commonSettings[
'MULTIPLE'][
'DESCRIPTION'] =
Loc::getMessage(
'MULTIPLE_DESCRIPTION');
556 unset($commonSettings[
'VALUE']);
558 $commonSettings[
'DEFAULT_VALUE'] = array(
560 'DESCRIPTION' =>
null,
561 'VALUE' => $this->property[
'DEFAULT_VALUE'],
565 if ($this->property[
'TYPE'] ===
'ENUM')
567 $defaultOptions = $this->
property[
'MULTIPLE'] ===
'Y'
571 if (!empty($this->property[
'VARIANTS']))
573 foreach ($this->property[
'VARIANTS'] as $row)
575 $defaultOptions[$row[
'VALUE']] = $row[
'NAME'];
579 $commonSettings[
'DEFAULT_VALUE'][
'OPTIONS'] = $defaultOptions;
581 elseif ($this->property[
'TYPE'] ===
'LOCATION')
583 if ($this->property[
'IS_LOCATION'] ===
'Y' || $this->property[
'IS_LOCATION4TAX'] ===
'Y')
585 unset($commonSettings[
'MULTIPLE']);
589 return $commonSettings;
594 return Manager::getSettings(
$property,
null);
600 'IS_PROFILE_NAME' => [
635 $orderProps = new \CSaleOrderProps();
639 $result = $orderProps->GetList([],
641 'PERSON_TYPE_ID' => $this->personTypeId,
645 false,
false, [
'ID',
'NAME']
647 while ($row = $result->Fetch())
649 $locationOptions[$row[
'ID']] = $row[
'NAME'];
659 'INPUT_FIELD_LOCATION' => [
663 'OPTIONS' => $locationOptions,
666 'IS_LOCATION4TAX' => [
678 'IS_ADDRESS_FROM' => [
680 'LABEL' =>
'IS_ADDRESS_FROM',
681 'DESCRIPTION' =>
'IS_ADDRESS_FROM'
685 'LABEL' =>
'IS_ADDRESS_TO',
686 'DESCRIPTION' =>
'IS_ADDRESS_TO'
695 'TYPE' =>
'STRING',
'LABEL' =>
Loc::getMessage(
'SALE_VARIANTS_CODE'),
'SIZE' =>
'5',
'MAXLENGTH' => 255,
'REQUIRED' =>
'Y'
698 'TYPE' =>
'STRING',
'LABEL' =>
Loc::getMessage(
'SALE_VARIANTS_NAME'),
'SIZE' =>
'20',
'MAXLENGTH' => 255,
'REQUIRED' =>
'Y'
701 'TYPE' =>
'NUMBER',
'LABEL' =>
Loc::getMessage(
'SALE_VARIANTS_SORT'),
'MIN' => 0,
'STEP' => 1,
'VALUE' => 100
704 'TYPE' =>
'STRING',
'LABEL' =>
Loc::getMessage(
'SALE_VARIANTS_DESCR'),
'SIZE' =>
'30',
'MAXLENGTH' => 255
707 'TYPE' =>
'NUMBER',
'MIN' => 0,
'STEP' => 1,
'HIDDEN' =>
'Y'
710 'TYPE' =>
'STRING',
'LABEL' =>
'XML_ID',
'SIZE' =>
'20',
'MAXLENGTH' => 255
717 $paymentOptions = array();
718 $result = \CSalePaySystem::GetList(
719 array(
"SORT"=>
"ASC",
"NAME"=>
"ASC"),
720 array(
"ACTIVE" =>
"Y"),
723 array(
"ID",
"NAME",
"ACTIVE",
"SORT",
"LID")
725 while ($row = $result->Fetch())
726 $paymentOptions[$row[
'ID']] = $row[
'NAME'] . ($row[
'LID'] ?
" ({$row['LID']}) " :
' ') .
"[{$row['ID']}]";
729 $deliveryOptions = array();
731 foreach(\
Bitrix\
Sale\
Delivery\Services\Manager::getActiveList(
true) as $deliveryId => $deliveryFields)
733 $name = $deliveryFields[
"NAME"].
" [".$deliveryId.
"]";
734 $sites = \Bitrix\Sale\Delivery\Restrictions\Manager::getSitesByServiceId($deliveryId);
737 $name .=
" (".implode(
", ", $sites).
")";
739 $deliveryOptions[$deliveryId] = $name;
743 'P' => [
'TYPE' =>
'ENUM',
'LABEL' =>
Loc::getMessage(
'SALE_PROPERTY_PAYSYSTEM'),
'OPTIONS' => $paymentOptions ,
'MULTIPLE' =>
'Y',
'SIZE' =>
'5'],
744 'D' => [
'TYPE' =>
'ENUM',
'LABEL' =>
Loc::getMessage(
'SALE_PROPERTY_DELIVERY' ),
'OPTIONS' => $deliveryOptions,
'MULTIPLE' =>
'Y',
'SIZE' =>
'5'],
755 if ($this->property[
'MULTIPLE'] ===
'Y')
760 if ($this->property[
'TYPE'] ===
'STRING')
764 elseif ($this->property[
'TYPE'] ===
'LOCATION')
768 if ($this->property[
'IS_LOCATION'] !==
'Y' || $this->property[
'MULTIPLE'] ===
'Y')
773 elseif ($this->property[
'TYPE'] ===
'ADDRESS')
781 if ($this->propertySettings ===
null)
792 foreach ($this->propertySettings as $name => $input)
794 if ($error = Manager::getError($input, $this->property[$name]))
796 if ($input[
'MULTIPLE'] && $input[
'MULTIPLE'] ===
'Y')
800 foreach ($error as $k => $v)
802 $errorString .=
' '.(++$k).
': '.implode(
', ', $v).
';';
805 $this->errors[] = $input[
'LABEL'].$errorString;
809 $this->errors[] = $input[
'LABEL'].
': '.implode(
', ', $error);
817 if (!empty($this->property))
822 foreach ($this->property[
'VARIANTS'] as $row)
826 if (isset($row[
'DELETE']) && $row[
'DELETE'] ===
'Y')
828 unset($this->propertySettings[
'DEFAULT_VALUE'][
'OPTIONS'][$row[
'VALUE']]);
834 foreach ($variantSettings as $name => $input)
836 if ($error = Manager::getError($input, $row[$name]))
838 $this->errors[] =
Loc::getMessage(
'INPUT_ENUM').
" $index: ".$input[
'LABEL'].
': '.implode(
', ', $error);
845 unset($this->propertySettings[
'DEFAULT_VALUE'][
'OPTIONS'][$row[
'VALUE']]);
856 foreach ($relationsSettings as $name => $input)
858 if (($value = $this->property[
'RELATIONS'][$name]) && $value != array(
''))
860 if ($error = Manager::getError($input, $value))
861 $errors [] = $input[
'LABEL'].
': '.implode(
', ', $error);
865 $relations[$name] = array();
875 if ($this->property[
'TYPE'] ===
'ENUM')
887 return !empty($this->errors);
892 $orderProps = new \CSaleOrderProps();
895 foreach ($relationsSettings as $name => $input)
897 $orderProps->UpdateOrderPropsRelations( $this->property[
'ID'], $this->property[
'RELATIONS'][$name], $name);
903 if ($this->property[
'TYPE'] ===
'FILE')
905 $savedFiles = $this->
saveFiles($this->property);
912 $propertiesToSave = [];
914 foreach ($this->propertySettings as $name => $input)
916 $inputValue = Manager::getValue($input, $this->property[$name]);
918 if ($name ===
'DEFAULT_VALUE' || $inputValue !==
null)
920 $propertiesToSave[$name] = $inputValue;
925 $propertiesToSave[
'SETTINGS'] = array_intersect_key($propertiesToSave, $inputSettings);
926 $propertiesToSave = array_diff_key($propertiesToSave, $propertiesToSave[
'SETTINGS']);
928 if (!empty($this->property[
'ID']))
933 if (!empty($this->property[
'ID']))
939 $this->
property[
'ID'] = $this->
addProperty($propertiesToSave);
953 $savedFiles = array();
955 $files = File::asMultiple(
$property[
'DEFAULT_VALUE']);
956 foreach ($files as $i => $file)
958 if (File::isDeletedSingle($file))
965 File::isUploadedSingle($file)
966 && ($fileId = \CFile::SaveFile(array(
'MODULE_ID' =>
'sale') + $file,
'sale/order/properties/default'))
967 && is_numeric($fileId)
971 $savedFiles[] = $fileId;
974 $files[$i] = File::loadInfoSingle($file);
985 if ($this->dbProperty ===
null)
993 if (empty($propertyId))
998 $property = \Bitrix\Sale\Internals\OrderPropsTable::getRow([
1000 '=ID' => $propertyId
1015 $propsVariant = new \CSaleOrderPropsVariant();
1023 $result = $propsVariant->GetList([], [
1026 while ($row = $result->Fetch())
1044 $orderProps = new \CSaleOrderProps();
1045 $result = $orderProps->GetOrderPropsRelations([
'PROPERTY_ID' =>
$property[
'ID']]);
1046 while ($row = $result->Fetch())
1048 if(RelationType::isDefined(RelationType::resolveID($row[
'ENTITY_TYPE'])))
1050 $property[
'RELATIONS'][$row[
'ENTITY_TYPE']][] = $row[
'ENTITY_ID'];
1059 $update = \Bitrix\Sale\Internals\OrderPropsTable::update(
1060 $this->property[
'ID'],
1061 array_diff_key($propertiesToSave, array(
'ID' => 1))
1063 if ($update->isSuccess())
1065 $propertyCode = $propertiesToSave[
'CODE'] ?:
false;
1067 $result = OrderPropsValueTable::getList([
'filter'=>[
1068 'ORDER_PROPS_ID' => $this->property[
'ID'],
1069 '!CODE' => $propertyCode,
1071 while ($row = $result->Fetch())
1073 OrderPropsValueTable::update($row[
'ID'], [
'CODE' => $propertyCode]);
1078 foreach ($update->getErrorMessages() as $errorMessage)
1080 $this->errors[] = $errorMessage;
1089 if(!isset($propertiesToSave[
'XML_ID']) && $propertiesToSave[
'XML_ID'] ==
'')
1091 $propertiesToSave[
'XML_ID'] = \Bitrix\Sale\Internals\OrderPropsTable::generateXmlId();
1094 $propertiesToSave[
'ENTITY_REGISTRY_TYPE'] = \Bitrix\Sale\Registry::REGISTRY_TYPE_ORDER;
1097 $addResult = \Bitrix\Sale\Internals\OrderPropsTable::add($propertiesToSave);
1098 if ($addResult->isSuccess())
1100 $propertyId = $addResult->getId();
1104 foreach ($addResult->getErrorMessages() as $errorMessage)
1106 $this->errors[] = $errorMessage;
1115 $filesToDelete = [];
1119 if (!empty($savedFiles))
1121 $filesToDelete = $savedFiles;
1126 if (!empty($this->dbProperty) && $this->dbProperty[
'TYPE'] ===
'FILE')
1128 $filesToDelete = File::asMultiple(File::getValue(
1129 $this->dbProperty, $this->dbProperty[
'DEFAULT_VALUE']
1132 if (!empty($savedFiles))
1134 $filesToDelete = array_diff(
1136 File::asMultiple(File::getValue($this->property, $this->property[
'DEFAULT_VALUE']))
1142 foreach ($filesToDelete as $fileId)
1144 if (is_numeric($fileId))
1146 \CFile::Delete($fileId);
1153 $orderPropsVariant = new \CSaleOrderPropsVariant();
1155 if ($this->property[
'TYPE'] ===
'ENUM')
1160 foreach ($this->property[
'VARIANTS'] as $key => $row)
1162 if (isset($row[
'DELETE']) && $row[
'DELETE'] ===
'Y')
1166 $orderPropsVariant->Delete($row[
'ID']);
1169 unset($this->property[
'VARIANTS'][$key]);
1174 $variantId = $row[
'ID'];
1175 $row = array_intersect_key($row, $variantSettings);
1180 if (!$orderPropsVariant->Update($variantId, $row))
1187 $row[
'ORDER_PROPS_ID'] = $this->
property[
'ID'];
1189 if ($variantId = $orderPropsVariant->Add($row))
1191 $variants[$key][
'ID'] = $variantId;
1202 elseif (!empty($this->dbProperty) && $this->dbProperty[
'TYPE'] ===
'ENUM')
1204 \CSaleOrderPropsVariant::DeleteAll($this->dbProperty[
'ID']);
1210 $fields[
'TYPE'] = mb_strtoupper($fields[
'TYPE']);
1217 if($name ==
'getfieldssettingsbytype'
1218 || $name ==
'getfieldsbytype'
1220 $r = $this->checkReadPermissionEntity();
1224 $r = parent::checkPermissionEntity($name);
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
updateProperty($propertiesToSave)
getPropertyGroupOptions()
getFieldsByTypeAction($type)
modifyDataDependedByType($property)
checkPermissionEntity($name)
updateAction($id, array $fields)
static prepareFields(array $fields)
getPersonType($personTypeId)
getInputSettings($property)
checkMultipleField($property)
loadProperty($propertyId)
addProperty($propertiesToSave)
initializeDbProperty($propertyId)
modifyRelationsDataDependedByType($property)
initializePropertySettings()
cleanUpFiles($savedFiles)
modifyInputSettingsByType(&$propertySettings)