A
A
Alexander2020-10-26 15:41:17
1C-Bitrix
Alexander, 2020-10-26 15:41:17

How to add a new infoblock element property via a script so that it is available only for a certain section?

The question is, is it possible to add new properties to products (infoblock elements) in the code using the Bitrix API, so that this property is available only for elements of a certain section of the catalog?

For example, there is a trade catalog (infoblock) - Electronics. The infoblock contains sections Mobile devices, Cameras and Laptops. The Exposure parameter is available only for products from the Cameras section. How can this parameter be in the code so that it is not displayed for elements of other sections?

By default, in order for the property to be displayed only for a specific product section,
in the infoblock settings, uncheck the Show on the list of elements page checkbox for the property and then indicate the desired property 5f96c31fdf480599838785.jpeg
in the required section in the Element Properties tab .
5f96c33172272291432574.jpeg

The second question, how can I make it so that after adding it through the script, the new property is immediately displayed in the Product tab?

5f96c3e3e6305134692338.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2020-10-26
@gromdron

This mechanism is not supplied in the box.
What is there?
1) Is it possible to add features (feature) to the property (property)?
Can. To do this, you need to supplement them on the OnPropertyFeatureBuildList event. There is no documentation, but digging the kernel in the \Bitrix\Iblock\Model\PropertyFeature class will help you
2) Is it possible to make certain properties be displayed depending on some conditions?
Yes and no. There is no such mechanism in the box, but you can completely redefine the form to edit the element .
But again, these changes will not display data in the product card (in the public part).
How is it usually done? They make a general element card, and then make several tabs for different sections.
By the way, it is good practice (and indeed very useful) not to make sections within one infoblock, but to create different infoblocks for different types of goods. This, of course, complicates the exchange with 1C (you will have to throw out what is out of the box and order your own), but it increases productivity and immediately solves such problems.

R
Roman Gritsuk, 2020-10-27
@winer

As far as I remember, there is such a class CIBlockSectionPropertyLink. He has these methods.

CIBlockSectionPropertyLink::Add($SECTION_ID, $PROPERTY_ID, $arLink = array())
CIBlockSectionPropertyLink::Delete($SECTION_ID, $PROPERTY_ID)
CIBlockSectionPropertyLink::DeleteByIBlock($IBLOCK_ID)
CIBlockSectionPropertyLink::DeleteByProperty($PROPERTY_ID)
CIBlockSectionPropertyLink::DeleteBySection($SECTION_ID)
CIBlockSectionPropertyLink::GetArray($IBLOCK_ID, $SECTION_ID = 0, $bNewSection = false)

https://dev.1c-bitrix.ru/community/webdev/user/898...
I don't remember how accurate this article is. If anything, examples of data can be viewed in the standard table b_iblock_section_property

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question