E
E
Evgeny Nikolaev2019-08-22 09:45:13
1C-Bitrix
Evgeny Nikolaev, 2019-08-22 09:45:13

How to set a list(enum) type property of an infoblock using api methods in bitrix?

Internet shop on Bitrix. There are goods and trade offers.
The trade offers infoblock has the "Size" property, code "SIZE". This property is a list (not plural).
How to change the property value using API methods (or set if not already set)?
A separate sub-question: Let's say I
have already created SIZE property list elements, for example, the following 4: "100*100","100*150","150*150","150*200"
suppose with code 100 to set the value of the property SIZE "300*400" which is not yet in the list. What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Nikolaev, 2020-01-20
@nikolaevevge

As a result, I wrote a function that takes 3 parameters: 1) the value that the list property should have, 2) the ID of the infoblock, 3) the property code - the function returns the ID of the existing property, and if it does not find it, it creates a record in the property and returns its ID. False is returned on error
Function code and usage examples here blog.ivru.net/?id=175
Directly on the question asked, the creation of goods or sales offers with a property binding of the list (enum) type is carried out as follows:

$el = new CIBlockElement;

$arLoadProductArray = array(
  "IBLOCK_ID"=>2, // IBLOCK торговых предложений
  "NAME"=>"Имя торгового предложения",
  "ACTIVE"=>"Y",
  "PROPERTY_VALUES"=>array(
    "CML2_LINK"=>$PRODUCT_ID, // Свойство типа "Привязка к товарам (SKU)", связываем торг. предложение с товаром
    "CML2_ARTICLE"=>"Артикул торгового предложения",
    "SIZE"=>$sizePropId,
    "CLOTH"=>$clothPropId
  )
);

$product_offer_id = $el->Add($arLoadProductArray);

In the code above, I have the SIZE and CLOTH properties of the list (enum) type in the $sizePropId and $clothPropId variables, the identifiers of the required property values ​​are passed.
To get the identifier by value, I provided a link to the corresponding function.

Y
Yaroslav Alexandrov, 2019-08-22
@alexyarik

1) Update list property
CIBlockPropertyEnum::GetList - get list property value ID
CIBlockElement::SetPropertyValues ​​- update element property using list property value ID
If list property value ID is empty, then:

$ibpenum = new CIBlockPropertyEnum;
if($PropID = $ibpenum->Add() 
{CIBlockElement::SetPropertyValues

More details here https://dev.1c-bitrix.ru/api_help/iblock/classes/c...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question