-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddNewElementToIblockTypeLists.php
85 lines (83 loc) · 2.44 KB
/
addNewElementToIblockTypeLists.php
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
<?php
class tMigration extends AbstractMigration
{
public function up()
{
if(!\Bitrix\Main\Loader::includeModule("iblock"))
{
return;
}
$resIblockTable = \Bitrix\Iblock\IblockTable::getList([
'filter'=>['CODE'=>"CONFIG_DOCUMENTS_CRM"],
'select'=>['ID']
])->fetch();
if($resIblockTable)
{
global $USER;
$el = new \CIBlockElement;
$PROP = array();
$html = <<<EOD
<html xml:lang="ua" lang="ua">
EOD;
$PROP["TEMPLATE_DOCUMENT"] = $html;
$arLoadProductArray = Array(
"MODIFIED_BY" => $USER->GetID(),
"IBLOCK_SECTION_ID" => false,
"IBLOCK_ID" => $resIblockTable['ID'],
"XML_ID" => "CALCULATING_RENTAL_COST",
"CODE" => "CALCULATING_RENTAL_COST",
"PROPERTY_VALUES"=> $PROP,
"NAME" => "Просчет стоимости проката",
"ACTIVE" => "Y", // активен
"PREVIEW_TEXT" => "",
"DETAIL_TEXT" => "",
"DETAIL_PICTURE" => "",
"WF_STATUS_ID" => 1,
);
if($PRODUCT_ID = $el->Add($arLoadProductArray))
{
echo "New ID: ".$PRODUCT_ID;
}
}
}
public function down()
{
if(!\Bitrix\Main\Loader::includeModule("iblock"))
{
return;
}
$resIblockTable = \Bitrix\Iblock\IblockTable::getList([
'filter'=>['CODE'=>"CONFIG_DOCUMENTS_CRM"],
'select'=>['ID']
])->fetch();
if($resIblockTable)
{
global $DB;
$rs = \CIBlockElement::GetList(
[],
[
'IBLOCK_ID'=>$resIblockTable['ID'],
'CODE'=>"TEST",
],
false,
false,
[
'ID',
'IBLOCK_ID'
]
);
if($res = $rs->fetch())
{
$DB->StartTransaction();
if(!\CIBlockElement::Delete($res['ID']))
{
$DB->Rollback();
}
else
{
$DB->Commit();
}
}
}
}
}