AddEventHandler("iblock", "OnAfterIBlockElementUpdate", "OnAfterIBlockElementUpdateHandler");
function OnAfterIBlockElementUpdateHandler(&$arFields)
{
CModule::IncludeModule('catalog');
global $APPLICATION;
$product = CCatalogProduct::GetByID($arFields['ID']);
$filename = '../../catalog/text.txt';
$fd = fopen($filename, "r");
$buf = fread($fd, 1024);
fclose($fd);
$bufer = unserialize($buf);
if (array_key_exists($arFields['ID'], $bufer) && $product['QUANTITY']>0):
$email = $bufer[$arFields['ID']]['EMAIL'];
unset($bufer[$arFields['ID']]);
foreach($email as $key=>$value):
$arEvent = Array(
"EMAIL"=>$value,
"NAME"=>$arFields['NAME']
);
CEvent::Send("REQUEST", 's1', $arEvent);
endforeach;
endif;
$fd = fopen($filename, "w");
fwrite($fd, serialize($bufer));
fclose($fd);
}
|