[bitrix] проверить связь тп -> товар

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
$cnt = 0;
$arFilter = Array("IBLOCK_ID" => 12, "!PROPERTY_CML2_ARTICLE" => false, "ACTIVE" => "Y");
$arOFilter = Array("IBLOCK_ID" => 13, "!PROPERTY_CML2_ARTICLE" => false);
$res = CIBlockElement::GetList(Array("show_counter" => "DESC"), $arOFilter, false, false, array("ID", "IBLOCK_ID","PROPERTY_CML2_ARTICLE"));
while($offer = $res->GetNext()) {
$article = $offer["PROPERTY_CML2_ARTICLE_VALUE"];
if($article) {
$arFilter = Array("IBLOCK_ID" => 12, "PROPERTY_CML2_ARTICLE" => $article);
$resdb = CIBlockElement::GetList(Array("show_counter" => "DESC"), $arFilter, false, array("nTopCount"=>1), array("ID", "IBLOCK_ID","PROPERTY_MODEL"));
if($prod = $resdb->GetNext()) {
$model = $prod["PROPERTY_MODEL_VALUE"];
if($model) {
$res_ib = CIBlockElement::GetList(Array("show_counter" => "DESC"), array("IBLOCK_ID" => 12, "PROPERTY_MODEL" => $model), false, array("nTopCount"=>1), array("ID", "IBLOCK_ID"));
if($primery = $res_ib->GetNext()) {
CIBlockElement::SetPropertyValuesEx($offer["ID"], 13, array(121 => $primery["ID"]));
$cnt++;
}
}
}
}
}
echo $cnt;