T
T
TheDrumkilla2020-02-26 10:50:36
1C-Bitrix
TheDrumkilla, 2020-02-26 10:50:36

How to prohibit changing the type of property when unloading from 1C?

Greetings. Products on the site have many properties, some of them need to be displayed in a smart filter as a slider with a range of "from" and "to". As you know, by default in Bitrix, only properties with the "number" type are displayed this way. From 1s, as a rule, properties are unloaded by the "list" type, which, for obvious reasons, does not suit me. With the help of a 1c programmer, we managed to force 1c to transfer some properties of the "string" type, well, at least they come to the site in this form. If we change the property type to a number, we get the desired functionality in the form of the notorious sliders.

Problem: after re-uploading, the property switches back to the string, and you have to manually click on all the properties and rearrange their type.

Question: Is it possible to "lock" the type for certain properties? What events can be used for this? Or maybe there is an opportunity to force 1C to give properties with the required type?

I will be grateful for help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton, 2020-02-26
@TheDrumkilla

1C returns an xml file, where everything is strings (no numbers)
The property has the following possible values: S - string, N - number, F - file, L - list, E - binding to elements, G - binding to groups.
--
This API changes the type from String to Number:

<?
require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("iblock");

$arFields = Array(
  "PROPERTY_TYPE" => "N", //ставим N если нужно число
  "IBLOCK_ID" => 2 //номер инфоблока
  );

$ibp = new CIBlockProperty;
if(!$ibp->Update(7, $arFields)) // где 7 это номер свойства (ID) в инфоблоке
    echo $ibp->LAST_ERROR; //выведем ошибку если ничего не получилось
?>

In fact, after unloading, you can run this code and the desired property will change the type.
spoiler
PS: Although, why the property type changes is not clear. It shouldn't be like that.

A
Aliy Kunashev, 2020-02-26
@askunash

If you are not satisfied with the import from 1C, there are 3 options (in ascending order of complexity):
1. Bring the data in 1C in line.
2. Bind to the OnBeforeCatalogImport1C event and override/overwrite the data.
3. Customize the exchange components - there is a standard exchange script, its address is in the store settings in the admin panel, follow a couple of steps of the included files - all the components are included there.
Everything.

A
Alexander Gruzdev, 2020-04-29
@Shuriban

a solution for automatically setting the desired property types.
In the local/php_interface/init.php file, or in the same one in the Bitrix folder.
We hang on the event before updating the properties.

AddEventHandler("iblock", "OnBeforeIBlockPropertyUpdate", "OnBeforeIBlockPropertyUpdateHandler");

function OnBeforeIBlockPropertyUpdateHandler(&$arFields){
//Проверяем, что идет обмен с 1С
    if (!empty($_GET['mode']) && $_GET['mode'] == 'import') {
        //сохраняем необходимые типы свойств инфоблока
        if ($arFields['NAME'] == 'Бренд' && $arFields['PROPERTY_TYPE'] !== 'E') {
            $arFields['PROPERTY_TYPE'] = 'E';
        }
        //для всех числовых свойств N

        $arPropertiesInt = [
            'Максимальная цена',
            'Объем камеры (л)',
            'Мощность охлаждения, Вт',
            'Потребл. мощность (Вт)',
            'Номин. мощность (Вт)',
            'Пиковая мощность (Вт)',
            'Расход топлива',
            'Мощность обогрева макс. (Вт)',
            'Расход газа (г/ч)',
            'Минимальная цена',
        ];
        if (in_array($arFields['NAME'], $arPropertiesInt) && $arFields['PROPERTY_TYPE'] !== 'N') {
            $arFields['PROPERTY_TYPE'] = 'N';
        }
    }
}

In the example, use the name of the property. You can use its ID, but not CODE.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question