1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
vat.php
См. документацию.
1
<?php
2
3
use
Bitrix\Main\Localization\Loc
;
4
use
Bitrix\Main\ORM
;
5
use
Bitrix\Catalog
;
6
7
class
CAllCatalogVat
8
{
17
public
static
function
CheckFields
(
$ACTION
, &
$arFields
,
$ID
= 0): bool
18
{
19
global
$APPLICATION
;
20
$arMsg =
array
();
21
$boolResult =
true
;
22
23
$ACTION
= mb_strtoupper(
$ACTION
);
24
if
(
'INSERT'
==
$ACTION
)
25
$ACTION
=
'ADD'
;
26
27
if
(isset(
$arFields
[
'SORT'
]))
28
{
29
$arFields
[
'C_SORT'
] =
$arFields
[
'SORT'
];
30
unset(
$arFields
[
'SORT'
]);
31
}
32
33
if
(array_key_exists(
'ID'
,
$arFields
))
34
{
35
unset(
$arFields
[
'ID'
]);
36
}
37
38
if
(
'ADD'
==
$ACTION
)
39
{
40
if
(!isset(
$arFields
[
'NAME'
]))
41
{
42
$boolResult =
false
;
43
$arMsg[] =
array
(
'id'
=>
'NAME'
,
"text"
=>
Loc::getMessage
(
'CVAT_ERROR_BAD_NAME'
));
44
}
45
if
(!isset(
$arFields
[
'RATE'
]))
46
{
47
$boolResult =
false
;
48
$arMsg[] =
array
(
'id'
=>
'RATE'
,
"text"
=>
Loc::getMessage
(
'CVAT_ERROR_BAD_RATE'
));
49
}
50
if
(!isset(
$arFields
[
'C_SORT'
]))
51
{
52
$arFields
[
'C_SORT'
] = 100;
53
}
54
if
(!isset(
$arFields
[
'ACTIVE'
]))
55
{
56
$arFields
[
'ACTIVE'
] =
'Y'
;
57
}
58
}
59
60
if
($boolResult)
61
{
62
if
(array_key_exists(
'NAME'
,
$arFields
))
63
{
64
$arFields
[
'NAME'
] = trim(
$arFields
[
'NAME'
]);
65
if
(
''
==
$arFields
[
'NAME'
])
66
{
67
$boolResult =
false
;
68
$arMsg[] =
array
(
'id'
=>
'NAME'
,
"text"
=>
Loc::getMessage
(
'CVAT_ERROR_BAD_NAME'
));
69
}
70
}
71
if
(array_key_exists(
'RATE'
,
$arFields
))
72
{
73
$arFields
[
'RATE'
] = doubleval(
$arFields
[
'RATE'
]);
74
if
(0 >
$arFields
[
'RATE'
] || 100 <
$arFields
[
'RATE'
])
75
{
76
$boolResult =
false
;
77
$arMsg[] =
array
(
'id'
=>
'RATE'
,
"text"
=>
Loc::getMessage
(
'CVAT_ERROR_BAD_RATE'
));
78
}
79
}
80
if
(array_key_exists(
'C_SORT'
,
$arFields
))
81
{
82
$arFields
[
'C_SORT'
] = intval(
$arFields
[
'C_SORT'
]);
83
if
(0 >=
$arFields
[
'C_SORT'
])
84
{
85
$arFields
[
'C_SORT'
] = 100;
86
}
87
}
88
if
(array_key_exists(
'ACTIVE'
,
$arFields
))
89
{
90
$arFields
[
'ACTIVE'
] = (
$arFields
[
'ACTIVE'
] ==
'Y'
?
'Y'
:
'N'
);
91
}
92
}
93
94
if
(!$boolResult)
95
{
96
$obError =
new
CAdminException
($arMsg);
97
$APPLICATION
->ResetException();
98
$APPLICATION
->ThrowException($obError);
99
}
100
return
$boolResult;
101
}
102
110
public
static
function
GetByID
(
$ID
)
111
{
112
return
CCatalogVat::GetListEx
(
array
(),
array
(
'ID'
=>
$ID
));
113
}
114
124
public
static
function
GetList
($arOrder =
array
(
'SORT'
=>
'ASC'
),
$arFilter
=
array
(),
$arFields
=
array
())
125
{
126
if
(is_array(
$arFilter
))
127
{
128
if
(array_key_exists(
'NAME'
,
$arFilter
) && array_key_exists(
'NAME_EXACT_MATCH'
,
$arFilter
))
129
{
130
if
(
'Y'
==
$arFilter
[
'NAME_EXACT_MATCH'
])
131
{
132
$arFilter
[
'=NAME'
] =
$arFilter
[
'NAME'
];
133
unset(
$arFilter
[
'NAME'
]);
134
}
135
unset(
$arFilter
[
'NAME_EXACT_MATCH'
]);
136
}
137
}
138
return
CCatalogVat::GetListEx
($arOrder,
$arFilter
,
false
,
false
,
$arFields
);
139
}
140
149
public
static
function
Set
(
$arFields
)
150
{
151
if
(isset(
$arFields
[
'ID'
]) && intval(
$arFields
[
'ID'
]) > 0)
152
{
153
return
CCatalogVat::Update
(
$arFields
[
'ID'
],
$arFields
);
154
}
155
else
156
{
157
return
CCatalogVat::Add
(
$arFields
);
158
}
159
}
160
161
public
static
function
GetByProductID
($PRODUCT_ID)
162
{
163
164
}
165
173
public
static
function
Add
(
$fields
)
174
{
175
if
(empty(
$fields
) || !is_array(
$fields
))
176
{
177
return
false
;
178
}
179
180
self::normalizeFields(
$fields
);
181
182
$result
=
Catalog\Model\Vat::add
(
$fields
);
183
184
$id =
false
;
185
if
(!
$result
->isSuccess())
186
{
187
self::convertErrors(
$result
);
188
}
189
else
190
{
191
$id = (int)
$result
->getId();
192
}
193
unset(
$result
);
194
195
return
$id;
196
}
197
206
public
static
function
Update
($id,
$fields
)
207
{
208
$id = (int)$id;
209
if
($id <= 0 || empty(
$fields
) || !is_array(
$fields
))
210
{
211
return
false
;
212
}
213
214
self::normalizeFields(
$fields
);
215
216
$result
=
Catalog\Model\Vat::update
($id,
$fields
);
217
218
if
(!
$result
->isSuccess())
219
{
220
$id =
false
;
221
self::convertErrors(
$result
);
222
}
223
224
return
$id;
225
}
226
234
public
static
function
Delete
($id): bool
235
{
236
$id = (int)$id;
237
if
($id <= 0)
238
{
239
return
false
;
240
}
241
242
$result
=
Catalog\Model\Vat::delete
($id);
243
$success
=
$result
->isSuccess();
244
if
(!
$success
)
245
{
246
self::convertErrors(
$result
);
247
}
248
unset(
$result
);
249
250
return
$success
;
251
}
252
253
private
static
function
normalizeFields(
array
&
$fields
): void
254
{
255
if
(!isset(
$fields
[
'SORT'
]))
256
{
257
if
(isset(
$fields
[
'C_SORT'
]))
258
{
259
$fields
[
'SORT'
] =
$fields
[
'C_SORT'
];
260
}
261
}
262
unset(
$fields
[
'C_SORT'
]);
263
}
264
265
private
static
function
convertErrors(ORM\Data\Result
$result
): void
266
{
267
global
$APPLICATION
;
268
269
$oldMessages = [];
270
foreach
(
$result
->getErrorMessages() as $errorText)
271
{
272
$oldMessages[] = [
273
'text'
=> $errorText,
274
];
275
}
276
unset($errorText);
277
278
if
(!empty($oldMessages))
279
{
280
$error
=
new
CAdminException($oldMessages);
281
$APPLICATION
->ThrowException(
$error
);
282
unset(
$error
);
283
}
284
unset($oldMessages);
285
}
286
}
$APPLICATION
global $APPLICATION
Определения
include.php:80
Bitrix\Catalog\Model\Entity\update
static update($id, array $data)
Определения
entity.php:229
Bitrix\Catalog\Model\Entity\add
static add(array $data)
Определения
entity.php:150
Bitrix\Catalog\Model\Entity\delete
static delete($id)
Определения
entity.php:317
Bitrix\Main\Localization\Loc
Определения
loc.php:12
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Определения
loc.php:30
CAdminException
Определения
adminexception.php:4
CAllCatalogVat
Определения
vat.php:8
CAllCatalogVat\Add
static Add($fields)
Определения
vat.php:173
CAllCatalogVat\Delete
static Delete($id)
Определения
vat.php:234
CAllCatalogVat\GetByID
static GetByID($ID)
Определения
vat.php:110
CAllCatalogVat\CheckFields
static CheckFields($ACTION, &$arFields, $ID=0)
Определения
vat.php:17
CAllCatalogVat\Update
static Update($id, $fields)
Определения
vat.php:206
CAllCatalogVat\Set
static Set($arFields)
Определения
vat.php:149
CAllCatalogVat\GetByProductID
static GetByProductID($PRODUCT_ID)
Определения
vat.php:161
CAllCatalogVat\GetList
static GetList($arOrder=array('SORT'=> 'ASC'), $arFilter=array(), $arFields=array())
Определения
vat.php:124
CCatalogVat\GetListEx
static GetListEx($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения
vat.php:7
$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
$result
$result
Определения
get_property_values.php:14
$ID
if($ajaxMode) $ID
Определения
get_user.php:27
$ACTION
$ACTION
Определения
csv_new_setup.php:27
$success
$success
Определения
mail_entry.php:69
Bitrix\Catalog
Bitrix\Main\ORM
$error
$error
Определения
subscription_card_product.php:20
$arFilter
$arFilter
Определения
user_search.php:106
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
catalog
general
vat.php
Создано системой
1.14.0