S
S
sagaton2021-11-06 16:08:58
1C-Bitrix
sagaton, 2021-11-06 16:08:58

How to set the xml_id of a property element like List?

The elements of the list type are specified as follows:
{ $iblockId = $this->getIblockIdByCode('clothes');
$propId = $this->addIblockElementProperty([
'ID' => '20',
'NAME' => 'Season',
'SORT' => 500,
'CODE' => 'Seasons',
'PROPERTY_TYPE' => ' L', // List
'LIST_TYPE' => 'C', // List type - 'checkboxes'
'SMART_FILTER' =>"Y",
'MULTIPLE' => 'Y',
'IS_REQUIRED' => 'Y',
'VALUES' =>
[ 'VALUE'[0] => 'Summer',
'VALUE' [1]=> 'Winter' ]); }

As a result, the name of the list element is specified as it should, but xml_id is generated automatically and has a character set.
As soon as I did not try to set it manually, I could not set it in any way.
Tell me, who knows how it would be correct to set xml for each element.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Zhitnik, 2021-11-07
@art-zhitnik

If this code works in the context of the Bitrix-migrations library, you can try this:

$propId = $this->addIblockElementProperty([
        ...
        'VALUES' => [
            [
                'VALUE' => 'Лето',
                'XML_ID' => 'summer',
            ],
            [
                'VALUE' => 'Зима',
                'XML_ID' => 'winter',
            ]
        ],
        ...
    ]);

S
sagaton, 2021-11-07
@sagaton

This one doesn't quite work. everything in VALUES is perceived as a property name, although if you write id it will still be a name. I found the solution here is part of the code.
$iblockId = $this->getIblockIdByCode('clothes');
$arFields = Array(
"ID" =>22,
"NAME" => "Season",
"ACTIVE" => "Y",
"SORT" => "600",
"CODE" => "Seasons",
"PROPERTY_TYPE " => "L",
'LIST_TYPE' => 'C', // List type - 'checkboxes'
'SMART_FILTER' =>"Y",
'
$arFields["VALUES"][0] = Array(
"XML_ID" => "Leto",
"VALUE" => "Summer",
"DEF" => "Y",
"SORT" => "100",
' DEF' => 'Y'
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question