S
S
spbty2020-07-03 23:11:33
1C-Bitrix
spbty, 2020-07-03 23:11:33

Check the infoblock field for uniqueness?

the Catalog infoblock has a custom field Article , tell me how you can implement it so that when adding a new product, this field is checked for uniqueness, i.e. if such an article already exists, then display a warning and prevent the product from being created

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mirexdoors, 2020-07-04
@spbty

Add an event handler before creating and modifying the element in which the check will take place

S
spbty, 2020-07-07
@spbty

who is interested in the solution, made such a handler in init.php

<?
AddEventHandler("iblock", "OnBeforeIBlockElementAdd",   array("СatalogAdd", "OnBeforeIBlockElementAdd"));
 

class СatalogAdd
{ 
   function OnBeforeIBlockElementAdd (&$arFields) 
     { 

CModule::IncludeModule("iblock"); 
$iblock_id = 6; // Указываем ID инфоблока
$arFilter = Array("IBLOCK_ID"=>$iblock_id,'PROPERTY_ARTICUL'=>(end(end($arFields['PROPERTY_VALUES']['13'])))); 
$res_count = CIBlockElement::GetList(Array(), $arFilter, Array(), false, Array()); // Получаем элементы инфоблока



     if ($res_count>0 and (end(end($arFields['PROPERTY_VALUES']['13'])))!="" ) {
          global $APPLICATION;
     $APPLICATION->throwException('Такой артикул уже есть');
            return false;  

     }
}
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question