Answer the question
In order to leave comments, you need to log in
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
Add an event handler before creating and modifying the element in which the check will take place
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 questionAsk a Question
731 491 924 answers to any question