1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
extra.php
См. документацию.
1
<?php
2
3
use
Bitrix\Main\Localization\Loc
;
4
use
Bitrix\Catalog
;
5
6
class
CAllExtra
7
{
8
protected
static
$arExtraCache
=
array
();
9
10
public
static
function
ClearCache
()
11
{
12
self::$arExtraCache =
array
();
13
}
14
15
public
static
function
GetByID
(
$ID
)
16
{
17
global
$DB
;
18
19
$ID
= (int)
$ID
;
20
if
(
$ID
<= 0)
21
return
false
;
22
23
if
(isset(self::$arExtraCache[
$ID
]))
24
{
25
return
self::$arExtraCache[
$ID
];
26
}
27
else
28
{
29
$strSql =
"SELECT ID, NAME, PERCENTAGE FROM b_catalog_extra WHERE ID = "
.$ID;
30
$db_res
=
$DB
->Query($strSql);
31
$res
=
$db_res
->Fetch();
32
if
(!empty(
$res
))
33
return
$res
;
34
}
35
return
false
;
36
}
37
38
public
static
function
SelectBox
($sFieldName, $sValue, $sDefaultValue =
""
, $JavaChangeFunc =
""
, $sAdditionalParams =
""
)
39
{
40
if
(empty(self::$arExtraCache))
41
{
42
self::$arExtraCache =
Catalog\ExtraTable::getExtraList
();
43
}
44
$s =
'<select name="'
.$sFieldName.
'"'
;
45
if
(!empty($JavaChangeFunc))
46
$s .=
' onchange="'
.$JavaChangeFunc.
'"'
;
47
if
(!empty($sAdditionalParams))
48
$s .=
' '
.$sAdditionalParams.
' '
;
49
$s .=
'>'
;
50
$sValue = intval($sValue);
51
$boolFound = isset(self::$arExtraCache[$sValue]);
52
if
(!empty($sDefaultValue))
53
$s .=
'<option value="0"'
.($boolFound ?
''
:
' selected'
).
'>'
.htmlspecialcharsex($sDefaultValue).
'</option>'
;
54
55
foreach
(self::$arExtraCache as &$arExtra)
56
{
57
$s .=
'<option value="'
.$arExtra[
'ID'
].
'"'
.($arExtra[
'ID'
] == $sValue ?
' selected'
:
''
).
'>'
.htmlspecialcharsex($arExtra[
'NAME'
]).
' ('
.htmlspecialcharsex($arExtra[
'PERCENTAGE'
]).
'%)</option>'
;
58
}
59
if
(isset($arExtra))
60
unset($arExtra);
61
return
$s.
'</select>'
;
62
}
63
64
public
static
function
Update
(
$ID
,
$arFields
)
65
{
66
global
$DB
;
67
68
$ID
= (int)
$ID
;
69
if
(
$ID
<= 0)
70
return
false
;
71
if
(!static::CheckFields(
'UPDATE'
,
$arFields
,
$ID
))
72
return
false
;
73
74
$strUpdate =
$DB
->PrepareUpdate(
"b_catalog_extra"
,
$arFields
);
75
if
(!empty($strUpdate))
76
{
77
$strSql =
"UPDATE b_catalog_extra SET "
.$strUpdate.
" WHERE ID = "
.
$ID
;
78
$DB
->Query($strSql);
79
80
if
(isset(
$arFields
[
'RECALCULATE'
]) &&
'Y'
==
$arFields
[
'RECALCULATE'
])
81
{
82
CPrice::ReCalculate
(
'EXTRA'
,
$ID
,
$arFields
[
'PERCENTAGE'
]);
83
}
84
static::ClearCache();
85
Catalog\ExtraTable::cleanCache
();
86
Catalog\Model\Price::clearSettings
();
87
}
88
89
return
true
;
90
}
91
92
public
static
function
Delete
(
$ID
)
93
{
94
global
$DB
;
95
$ID
= (int)
$ID
;
96
if
(
$ID
<= 0)
97
return
false
;
98
$DB
->Query(
"UPDATE b_catalog_price SET EXTRA_ID = NULL WHERE EXTRA_ID = "
.
$ID
);
99
static::ClearCache();
100
Catalog\ExtraTable::cleanCache
();
101
Catalog\Model\Price::clearSettings
();
102
103
return
$DB
->Query(
"DELETE FROM b_catalog_extra WHERE ID = "
.
$ID
,
true
);
104
}
105
106
public
static
function
CheckFields
($strAction, &
$arFields
,
$ID
= 0)
107
{
108
global
$APPLICATION
;
109
110
$arMsg =
array
();
111
$boolResult =
true
;
112
113
$strAction = mb_strtoupper($strAction);
114
115
$ID
= (int)
$ID
;
116
if
(
'UPDATE'
== $strAction && 0 >=
$ID
)
117
{
118
$arMsg[] =
array
(
'id'
=>
'ID'
,
'text'
=>
Loc::getMessage
(
'CAT_EXTRA_ERR_UPDATE_NOT_ID'
));
119
$boolResult =
false
;
120
}
121
if
(array_key_exists(
'ID'
,
$arFields
))
122
{
123
unset(
$arFields
[
'ID'
]);
124
}
125
126
if
(
'ADD'
== $strAction)
127
{
128
if
(!array_key_exists(
'NAME'
,
$arFields
))
129
{
130
$arMsg[] =
array
(
'id'
=>
'NAME'
,
'text'
=>
Loc::getMessage
(
'CAT_EXTRA_ERROR_NONAME'
));
131
$boolResult =
false
;
132
}
133
if
(!array_key_exists(
'PERCENTAGE'
,
$arFields
))
134
{
135
$arMsg[] =
array
(
'id'
=>
'PERCENTAGE'
,
'text'
=>
Loc::getMessage
(
'CAT_EXTRA_ERROR_NOPERCENTAGE'
));
136
$boolResult =
false
;
137
}
138
}
139
140
if
($boolResult)
141
{
142
if
(array_key_exists(
'NAME'
,
$arFields
))
143
{
144
$arFields
[
"NAME"
] = trim(
$arFields
[
"NAME"
]);
145
if
(
''
==
$arFields
[
"NAME"
])
146
{
147
$arMsg[] =
array
(
'id'
=>
'NAME'
,
'text'
=>
Loc::getMessage
(
'CAT_EXTRA_ERROR_NONAME'
));
148
$boolResult =
false
;
149
}
150
}
151
if
(array_key_exists(
'PERCENTAGE'
,
$arFields
))
152
{
153
$arFields
[
"PERCENTAGE"
] = trim(
$arFields
[
"PERCENTAGE"
]);
154
if
(
''
==
$arFields
[
"PERCENTAGE"
])
155
{
156
$arMsg[] =
array
(
'id'
=>
'PERCENTAGE'
,
'text'
=>
Loc::getMessage
(
'CAT_EXTRA_ERROR_NOPERCENTAGE'
));
157
$boolResult =
false
;
158
}
159
else
160
{
161
$arFields
[
"PERCENTAGE"
] = doubleval(
$arFields
[
"PERCENTAGE"
]);
162
}
163
}
164
}
165
166
if
(!$boolResult)
167
{
168
$obError =
new
CAdminException
($arMsg);
169
$APPLICATION
->ResetException();
170
$APPLICATION
->ThrowException($obError);
171
}
172
return
$boolResult;
173
}
174
182
public
static
function
PrepareInsert
(&
$arFields
, &$intID)
183
{
184
return
false
;
185
}
186
}
$db_res
$db_res
Определения
options_user_settings.php:8
$APPLICATION
global $APPLICATION
Определения
include.php:80
Bitrix\Catalog\ExtraTable\getExtraList
static getExtraList()
Определения
extra.php:124
Bitrix\Catalog\Model\Price\clearSettings
static clearSettings()
Определения
price.php:762
Bitrix\Main\Localization\Loc
Определения
loc.php:12
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Определения
loc.php:30
Bitrix\Main\ORM\Data\DataManager\cleanCache
static cleanCache()
Определения
datamanager.php:1983
CAdminException
Определения
adminexception.php:4
CAllExtra
Определения
extra.php:7
CAllExtra\PrepareInsert
static PrepareInsert(&$arFields, &$intID)
Определения
extra.php:182
CAllExtra\SelectBox
static SelectBox($sFieldName, $sValue, $sDefaultValue="", $JavaChangeFunc="", $sAdditionalParams="")
Определения
extra.php:38
CAllExtra\Delete
static Delete($ID)
Определения
extra.php:92
CAllExtra\GetByID
static GetByID($ID)
Определения
extra.php:15
CAllExtra\$arExtraCache
static $arExtraCache
Определения
extra.php:8
CAllExtra\ClearCache
static ClearCache()
Определения
extra.php:10
CAllExtra\Update
static Update($ID, $arFields)
Определения
extra.php:64
CAllExtra\CheckFields
static CheckFields($strAction, &$arFields, $ID=0)
Определения
extra.php:106
CAllPrice\ReCalculate
static ReCalculate($TYPE, $ID, $VAL)
Определения
price.php:377
$arFields
$arFields
Определения
dblapprove.php:5
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$ID
if($ajaxMode) $ID
Определения
get_user.php:27
$DB
global $DB
Определения
cron_frame.php:29
Bitrix\Catalog
bitrix
modules
catalog
general
extra.php
Создано системой
1.14.0