require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php"); CModule::IncludeModule("iblock"); CModule::IncludeModule("catalog"); $iblock_id = 16; $idPropSale = 213; $oldPropsSale = $arNewSale = array(); $resItem = CIBlockElement::GetList( array("ID"=>"asc"), array( "ACTIVE"=>"Y", "IBLOCK_ID"=>$iblock_id), false, false, array("ID", "IBLOCK_ID", "PROPERTY_SPECIALOFFER") ); while($arItem = $resItem->Fetch()) { $oldPropsSale[$arItem["ID"]] = $arItem["PROPERTY_SPECIALOFFER_VALUE"]; $offersExist = CCatalogSKU::getExistOffers($arItem["ID"], $arItem["IBLOCK_ID"]); if($offersExist[$arItem["ID"]] == 1) { $resSku = CCatalogSKU::getOffersList( $arItem["ID"], $arItem["IBLOCK_ID"], array("ACTIVE"=>"Y") ); if(!empty($resSku[$arItem["ID"]])) { foreach($resSku[$arItem["ID"]] as $sku) { $arDiscounts = CCatalogDiscount::GetDiscountByProduct($sku["ID"], array(2), "N", 1, SITE_ID); if(!empty($arDiscounts)) { $arNewSale[$sku["PARENT_ID"]] = "Y"; break; } } } } else { $arDiscounts = CCatalogDiscount::GetDiscountByProduct($arItem["ID"], array(2), "N", 1, SITE_ID); if(!empty($arDiscounts)) { $arNewSale[$arItem["ID"]] = "Y"; } } } foreach($arNewSale as $prodId => $propVal) { if($oldPropsSale[$prodId] != "yes" && $propVal == "Y") { CIBlockElement::SetPropertyValuesEx($prodId, $iblock_id, array("SPECIALOFFER" => $idPropSale)); } } foreach($oldPropsSale as $prodId => $propVal) { if($oldPropsSale[$prodId] == "yes" && $arNewSale[$prodId] != "Y") { CIBlockElement::SetPropertyValuesEx($prodId, $iblock_id, array("SPECIALOFFER" => false)); } }