создание ТП для всех типов товаров

 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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);
$arOFilter = Array("IBLOCK_ID" => 13);
$res = CIBlockElement::GetList(Array("ID" => "DESC"), $arFilter, false, false, $arSelect);
while ($fields = $res->GetNext()) {
$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())) {
$arLoadProductArray = Array(
"IBLOCK_SECTION_ID" => false, // элемент лежит в корне раздела
"IBLOCK_ID" => 13,
"PROPERTY_VALUES" => array(
"CML2_ARTICLE" => $fields["PROPERTY_CML2_ARTICLE_VALUE"],
"CML2_COLOR" => $fields["PROPERTY_COLOR_VALUE"],
"CML2_SIZE" => $fields["PROPERTY_SIZE_VALUE"],
),
"NAME" => $fields["NAME"],
"ACTIVE" => $fields["ACTIVE"]
);
if (trim($fields["PROPERTY_MODEL_VALLUE"]) == "") {
$pid = $fields["ID"];
} else {
$arFilter["PROPERTY_MODEL"] = $fields["PROPERTY_MODEL_VALLUE"];
$resModel = CIBlockElement::GetList(
Array("show_counter" => "desc"), $arFilter, false, false, array("ID", "IBLOCK_ID")
);
$cntModels = $resModel->SelectedRowsCount();
if ($model = $resModel->GetNext() && $cntModels > 1) {
$pid = $model["ID"];
}
}
$arLoadProductArray["PROPERTY_VALUES"]["CML2_LINK"] = $pid;
if ($OFFER_ID = $el->Add($arLoadProductArray)) {
CCatalogProduct::Add(Array("ID" => $OFFER_ID, "QUANTITY" => $fields["CATALOG_QUANTITY"]));
CPrice::Add(
array(
"PRODUCT_ID" => $OFFER_ID,
"PRICE" => $fields["CATALOG_PRICE_3"],
"CATALOG_GROUP_ID" => 3,
"CURRENCY" => "RUB"
)
);
if ($fields["CATALOG_PRICE_2"] > 0) {
CPrice::Add(
array(
"PRODUCT_ID" => $OFFER_ID,
"PRICE" => $fields["CATALOG_PRICE_2"],
"CATALOG_GROUP_ID" => 2,
"CURRENCY" => "RUB"
)
);
}
$offerStores = array();
$rsStore = CCatalogStoreProduct::GetList(
array("ID" => "DESC"), array('PRODUCT_ID' => $pid), false, false, array("STORE_ID", "AMOUNT")
);
while ($arStore = $rsStore->Fetch()) {
$arStoreFields = $arStore;
$arStoreFields["PRODUCT_ID"] = $OFFER_ID;
$ID = CCatalogStoreProduct::Add($arStoreFields);
}
$cnt++;
if ($fields["ACTIVE"] == "Y") {
echo $fields["PROPERTY_CML2_ARTICLE_VALUE"] . "<br />";
}
}
} else {
CIBlockElement::SetPropertyValuesEx($OFields["ID"], 13, array("CML2_LINK" => $pid));
echo "<span style='color:red;'>нет привязки: </span>" . $fields["PROPERTY_CML2_ARTICLE_VALUE"] . "<br />";
}
}
DebugInfo::d($cnt);