Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bxtimur/4898148e97d3818defec23b55eaee045 to your computer and use it in GitHub Desktop.
Save bxtimur/4898148e97d3818defec23b55eaee045 to your computer and use it in GitHub Desktop.
// Uniqueness of the element's code
AddEventHandler("iblock", "OnAfterIBlockElementAdd", "UniquenessCode");
function UniquenessCode (&$arFields) {
if ($arFields["IBLOCK_ID"] == CATALOG_IBLOCK_ID && !empty($arFields["CODE"])) {
$code = $arFields["CODE"] . "-" . $arFields["ID"];
$code = str_replace("--", "-", $code);
$objElement = new CIBlockElement;
$objElement->Update($arFields["ID"], array("CODE" => $code));
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment