pm: решение с кнопкой купить

 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
41
42
43
// ===========================
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
$el = new CIBlockElement;
$arSelect = Array(
"ID", "IBLOCK_ID", /*"NAME", */"ACTIVE", /*"CODE", */"PROPERTY_CML2_ARTICLE", "PROPERTY_MODEL"/*, "PROPERTY_COLOR",
"PROPERTY_SIZE", "CATALOG_GROUP_3", "CATALOG_GROUP_2"*/
);
$arFilter = Array("IBLOCK_ID" => 12, "!PROPERTY_CML2_ARTICLE" => false, "ACTIVE" => "Y");
$arOFilter = Array("IBLOCK_ID" => 13);
$res = CIBlockElement::GetList(Array("ID" => "DESC"), $arFilter, false, false, $arSelect);
while ($fields = $res->GetNext()) {
/* родительский элемент */
$pid = $fields["ID"];
if (trim($fields["PROPERTY_MODEL_VALUE"]) != "") {
$arFilter["PROPERTY_MODEL"] = $fields["PROPERTY_MODEL_VALUE"];
$resModel = CIBlockElement::GetList(
Array("show_counter" => "desc"), $arFilter, false, false, array("ID", "IBLOCK_ID")
);
$cntModels = $resModel->SelectedRowsCount();
//DebugInfo::d($cntModels,"моделей");
if($cntModels > 1){
if ($model = $resModel->GetNext()) {
//DebugInfo::d($model,'model');
echo "<span style='color:green;'>модель (pid,".$model['ID']."): </span>" . $fields["PROPERTY_MODEL_VALUE"] . "<br />";
$pid = $model["ID"];
}
}
}
$arOFilter["PROPERTY_CML2_ARTICLE"] = $fields["PROPERTY_CML2_ARTICLE_VALUE"];
$resOffers = CIBlockElement::GetList(Array("ID" => "DESC"), $arOFilter, false, array("nTopCount" => 1), array("ID", "IBLOCK_ID"));
if ($OFields = $resOffers->GetNext()) {
//DebugInfo::d($pid,'у кого меняем');
CIBlockElement::SetPropertyValuesEx($OFields["ID"], 13, array(121 => $pid));
echo "<span style='color:red;'>нет привязки: </span>" . $fields["PROPERTY_CML2_ARTICLE_VALUE"] . "<br />";
}
}
// ===========================