товары, с отсутствующей моделью и несколькими ТП

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
$el = new CIBlockElement;
$arSelect = Array(
"ID", "IBLOCK_ID", "NAME", "ACTIVE", "PROPERTY_CML2_ARTICLE"
);
$arFilter = Array("IBLOCK_ID" => 12, "!PROPERTY_CML2_ARTICLE" => false, "ACTIVE" => "Y", "PROPERTY_MODEL" => false);
$arOFilter = Array("IBLOCK_ID" => 13);
$res = CIBlockElement::GetList(Array("ID" => "DESC"), $arFilter, false, false, $arSelect);
while ($fields = $res->GetNext()) {
/* родительский элемент */
$pid = $fields["ID"];
$arOFilter["PROPERTY_CML2_LINK"] = $pid;
$resOffers = CIBlockElement::GetList(Array("ID" => "DESC"), $arOFilter, false, false, array("ID", "IBLOCK_ID", "PROPERTY_CML2_ARTICLE"));
$cntModels = $resOffers->SelectedRowsCount();
if($cntModels>1){
$cnt++;
while ($fieldsOffers = $resOffers->GetNext()) {
$arFilter["PROPERTY_CML2_ARTICLE"] = $fieldsOffers["PROPERTY_CML2_ARTICLE_VALUE"];
unset($arFilter["ACTIVE"]);
unset($arFilter["!PROPERTY_CML2_ARTICLE"]);
unset($arFilter["PROPERTY_MODEL"]);
$resOff = CIBlockElement::GetList(Array("show_counter" => "desc"), $arFilter, false, array("nTopCount"=>1), $arSelect);
if($arElement = $resOff->GetNext()) {
DebugInfo::d($arElement,$fieldsOffers["ID"]);
CIBlockElement::SetPropertyValuesEx($fieldsOffers["ID"], 13, array(121 => $arElement["ID"]));
}
//
}
}
}
echo "кол-во: " . $cnt;