4namespace Bitrix\Sale\Controller;
8use Bitrix\Main\Engine\Response\DataType\Page;
9use Bitrix\Main\Entity\ExpressionField;
11use Bitrix\Main\Localization\Loc;
12use Bitrix\Main\UI\PageNavigation;
13use Bitrix\Sale\EntityProperty;
14use Bitrix\Sale\Internals\Input\File;
15use Bitrix\Sale\Internals\Input\Manager;
16use Bitrix\Sale\Internals\OrderPropsValueTable;
17use Bitrix\Sale\Registry;
18use Bitrix\Sale\Rest\Entity\RelationType;
19use Bitrix\Sale\Result;
21Loc::loadMessages(
$_SERVER[
"DOCUMENT_ROOT"].
'/bitrix/modules/sale/admin/order_props_edit.php');
40 $r->addError(
new Error(
'type is out of range', 200850000008));
50 $entity = new \Bitrix\Sale\Rest\Entity\Property();
51 return [
'PROPERTY'=>
$entity->prepareFieldInfos(
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'];
78 $this->personTypeId =
$fields[
'PERSON_TYPE_ID'];
79 $this->
property = $fields;
87 foreach ($this->errors as
$error)
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));
152 $propertyClassName = $this->getPropertyClassName();
154 $items = $propertyClassName::getList(
159 'offset' => $pageNavigation->
getOffset(),
160 'limit' => $pageNavigation->
getLimit(),
167 $propertyClassName = $this->getPropertyClassName();
169 return (
int) $propertyClassName::getList([
184 return \Bitrix\Sale\Property::class;
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'];
220 foreach ($this->errors as
$error)
233 return [
'PROPERTY'=>$this->
get($this->
property[
'ID'])];
244 if(isset(
$fields[
'IS_FILTERED']) ==
false)
246 $r->addError(
new Error(
'Require fields: isFiltered.' , 200850000009));
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));
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));
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));
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');
313 'LABEL'=>Loc::getMessage(
'F_DEFAULT_VALUE')
318 if (
$type ===
'STRING')
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;
393 'PERSON_TYPE_ID' => [
395 'LABEL' => Loc::getMessage(
'SALE_PERS_TYPE'),
401 'PROPS_GROUP_ID' => [
403 'LABEL' => Loc::getMessage(
'F_PROPS_GROUP_ID'),
407 'LABEL' => Loc::getMessage(
'F_NAME'),
413 'LABEL' => Loc::getMessage(
'F_CODE'),
418 'LABEL' => Loc::getMessage(
'F_ACTIVE'),
423 'LABEL' => Loc::getMessage(
'F_UTIL')
427 'LABEL' => Loc::getMessage(
'F_USER_PROPS')
431 'LABEL' => Loc::getMessage(
'F_IS_FILTERED'),
432 'DESCRIPTION' => Loc::getMessage(
'MULTIPLE_DESCRIPTION')
436 'LABEL' => Loc::getMessage(
'F_SORT'),
443 'LABEL' => Loc::getMessage(
'F_DESCRIPTION'),
457 'PERSON_TYPE_ID' => [
459 'LABEL' => Loc::getMessage(
'SALE_PERS_TYPE'),
464 'RLABEL' => $personType[
'NAME']
466 'PROPS_GROUP_ID' => [
468 'LABEL' => Loc::getMessage(
'F_PROPS_GROUP_ID'),
469 'OPTIONS' => $groupOptions
473 'LABEL' => Loc::getMessage(
'F_NAME'),
479 'LABEL' => Loc::getMessage(
'F_CODE'),
484 'LABEL' => Loc::getMessage(
'F_ACTIVE'),
489 'LABEL' => Loc::getMessage(
'F_UTIL')
493 'LABEL' => Loc::getMessage(
'F_USER_PROPS')
497 'LABEL' => Loc::getMessage(
'F_IS_FILTERED'),
498 'DESCRIPTION' => Loc::getMessage(
'MULTIPLE_DESCRIPTION')
502 'LABEL' => Loc::getMessage(
'F_SORT'),
509 'LABEL' => Loc::getMessage(
'F_DESCRIPTION'),
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'],
562 'LABEL' => Loc::getMessage(
'F_DEFAULT_VALUE'),
565 if ($this->property[
'TYPE'] ===
'ENUM')
567 $defaultOptions = $this->
property[
'MULTIPLE'] ===
'Y'
569 : [
'' => Loc::getMessage(
'NO_DEFAULT_VALUE')];
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' => [
602 'LABEL' => Loc::getMessage(
'F_IS_PROFILE_NAME'),
603 'DESCRIPTION' => Loc::getMessage(
'F_IS_PROFILE_NAME_DESCR')
607 'LABEL' => Loc::getMessage(
'F_IS_PAYER'),
608 'DESCRIPTION' => Loc::getMessage(
'F_IS_PAYER_DESCR')
612 'LABEL' => Loc::getMessage(
'F_IS_EMAIL'),
613 'DESCRIPTION' => Loc::getMessage(
'F_IS_EMAIL_DESCR')
617 'LABEL' => Loc::getMessage(
'F_IS_PHONE'),
618 'DESCRIPTION' => Loc::getMessage(
'F_IS_PHONE_DESCR')
622 'LABEL' => Loc::getMessage(
'F_IS_ZIP'),
623 'DESCRIPTION' => Loc::getMessage(
'F_IS_ZIP_DESCR')
627 'LABEL' => Loc::getMessage(
'F_IS_ADDRESS'),
628 'DESCRIPTION' => Loc::getMessage(
'F_IS_ADDRESS_DESCR')
635 $orderProps = new \CSaleOrderProps();
637 $locationOptions = [
'' => Loc::getMessage(
'NULL_ANOTHER_LOCATION')];
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'];
655 'LABEL' => Loc::getMessage(
'F_IS_LOCATION'),
656 'DESCRIPTION' => Loc::getMessage(
'F_IS_LOCATION_DESCR'),
659 'INPUT_FIELD_LOCATION' => [
661 'LABEL' => Loc::getMessage(
'F_ANOTHER_LOCATION'),
662 'DESCRIPTION' => Loc::getMessage(
'F_INPUT_FIELD_DESCR'),
663 'OPTIONS' => $locationOptions,
666 'IS_LOCATION4TAX' => [
668 'LABEL' => Loc::getMessage(
'F_IS_LOCATION4TAX'),
669 'DESCRIPTION' => Loc::getMessage(
'F_IS_LOCATION4TAX_DESCR'),
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();
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();
733 $name = $deliveryFields[
"NAME"].
" [".$deliveryId.
"]";
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')
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))
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();
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))
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'];
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]);
1089 if(!isset($propertiesToSave[
'XML_ID']) && $propertiesToSave[
'XML_ID'] ==
'')
1098 if ($addResult->isSuccess())
1100 $propertyId = $addResult->getId();
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))
1182 $this->errors[] = Loc::getMessage(
'ERROR_EDIT_VARIANT').
" $index";
1187 $row[
'ORDER_PROPS_ID'] = $this->
property[
'ID'];
1189 if ($variantId = $orderPropsVariant->Add($row))
1191 $variants[
$key][
'ID'] = $variantId;
1195 $this->errors[] = Loc::getMessage(
'ERROR_ADD_VARIANT').
" $index";
1202 elseif (!empty($this->dbProperty) && $this->dbProperty[
'TYPE'] ===
'ENUM')
1217 if(
$name ==
'getfieldssettingsbytype'
1218 ||
$name ==
'getfieldsbytype'
1220 $r = $this->checkReadPermissionEntity();
1224 $r = parent::checkPermissionEntity(
$name);
static getRow(array $parameters)
static update($primary, array $data)
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)
static load($siteId=null, $id=null)
const REGISTRY_TYPE_ORDER
static getSitesByServiceId($id)
static GetList($arOrder=array("SORT"=> "ASC", "NAME"=> "ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
$_SERVER["DOCUMENT_ROOT"]
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key