1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
measure_ratio.php
См. документацию.
1
<?php
2
3
use
Bitrix\Main\Localization\Loc
;
4
use
Bitrix\Catalog
;
5
6
class
CCatalogMeasureRatioAll
7
{
8
protected
static
$whiteList
=
array
(
'ID'
,
'PRODUCT_ID'
,
'RATIO'
,
'IS_DEFAULT'
);
9
10
protected
static
function
checkFields
(
$action
, &
$arFields
)
11
{
13
global
$APPLICATION
;
14
15
$action
= mb_strtoupper(
$action
);
16
if
(
$action
!=
'UPDATE'
&&
$action
!=
'ADD'
)
17
{
18
$APPLICATION
->ThrowException(
Loc::getMessage
(
'CATALOG_MEASURE_RATIO_BAD_ACTION'
));
19
return
false
;
20
}
21
$clearFields =
array
();
22
foreach
(self::$whiteList as $field)
23
{
24
if
($field ==
'ID'
)
25
continue
;
26
if
(isset(
$arFields
[$field]))
27
$clearFields[$field] =
$arFields
[$field];
28
}
29
unset($field);
30
31
if
(
$action
==
'ADD'
)
32
{
33
if
(empty($clearFields))
34
{
35
$APPLICATION
->ThrowException(
Loc::getMessage
(
'CATALOG_MEASURE_RATIO_EMPTY_CLEAR_FIELDS'
));
36
return
false
;
37
}
38
if
(!isset($clearFields[
'PRODUCT_ID'
]))
39
{
40
$APPLICATION
->ThrowException(
Loc::getMessage
(
'CATALOG_MEASURE_RATIO_PRODUCT_ID_IS_ABSENT'
));
41
return
false
;
42
}
43
if
(!isset($clearFields[
'RATIO'
]))
44
$clearFields[
'RATIO'
] = 1;
45
if
(!isset($clearFields[
'IS_DEFAULT'
]))
46
{
47
$row =
null
;
48
if
((
int
)$clearFields[
'PRODUCT_ID'
] > 0)
49
{
50
$row = Catalog\MeasureRatioTable::getList(
array
(
51
'select'
=>
array
(
'ID'
),
52
'filter'
=>
array
(
'=PRODUCT_ID'
=> $clearFields[
'PRODUCT_ID'
],
'=IS_DEFAULT'
=>
'Y'
)
53
))->fetch();
54
}
55
$clearFields[
'IS_DEFAULT'
] = (!empty($row) ?
'N'
:
'Y'
);
56
unset($row);
57
}
58
}
59
if
(isset($clearFields[
'PRODUCT_ID'
]))
60
{
61
$clearFields[
'PRODUCT_ID'
] = (int)$clearFields[
'PRODUCT_ID'
];
62
if
($clearFields[
'PRODUCT_ID'
] <= 0)
63
{
64
$APPLICATION
->ThrowException(
Loc::getMessage
(
'CATALOG_MEASURE_RATIO_BAD_PRODUCT_ID'
));
65
return
false
;
66
}
67
}
68
if
(isset($clearFields[
'RATIO'
]))
69
{
70
if
(is_string($clearFields[
'RATIO'
]))
71
$clearFields[
'RATIO'
] = str_replace(
','
,
'.'
, $clearFields[
'RATIO'
]);
72
$clearFields[
'RATIO'
] = (float)$clearFields[
'RATIO'
];
73
if
($clearFields[
'RATIO'
] <=
CATALOG_VALUE_EPSILON
)
74
$clearFields[
'RATIO'
] = 1;
75
}
76
if
(isset($clearFields[
'IS_DEFAULT'
]))
77
$clearFields[
'IS_DEFAULT'
] = ($clearFields[
'IS_DEFAULT'
] ==
'Y'
?
'Y'
:
'N'
);
78
$arFields
= $clearFields;
79
unset($clearFields);
80
81
return
true
;
82
}
83
95
public
static
function
add
(
$arFields
)
96
{
97
if
(!static::checkFields(
'ADD'
,
$arFields
))
98
return
false
;
99
100
$existRatio = Catalog\MeasureRatioTable::getList(
array
(
101
'select'
=>
array
(
'ID'
),
102
'filter'
=>
array
(
'=PRODUCT_ID'
=>
$arFields
[
'PRODUCT_ID'
],
'=RATIO'
=>
$arFields
[
'RATIO'
])
103
))->fetch();
104
if
(!empty($existRatio))
105
return
(
int
)$existRatio[
'ID'
];
106
107
$result
= Catalog\MeasureRatioTable::add(
$arFields
);
108
if
(
$result
->isSuccess())
109
return
(
int
)
$result
->getId();
110
112
global
$APPLICATION
;
113
$errorList =
$result
->getErrorMessages();
114
if
(!empty($errorList))
115
$APPLICATION
->ThrowException(implode(
', '
, $errorList));
116
unset($errorList,
$result
);
117
return
false
;
118
}
119
132
public
static
function
update
($id,
$arFields
)
133
{
135
global
$APPLICATION
;
136
137
$id = (int)$id;
138
if
($id <= 0 || !static::checkFields(
'UPDATE'
,
$arFields
))
139
return
false
;
140
if
(empty(
$arFields
))
141
return
$id;
142
143
$existRatio = Catalog\MeasureRatioTable::getList(
array
(
144
'select'
=>
array
(
'ID'
),
145
'filter'
=>
array
(
'!=ID'
=> $id,
'=PRODUCT_ID'
=>
$arFields
[
'PRODUCT_ID'
],
'=RATIO'
=>
$arFields
[
'RATIO'
])
146
))->fetch();
147
if
(!empty($existRatio))
148
{
149
$APPLICATION
->ThrowException(
Loc::getMessage
(
150
'CATALOG_MEASURE_RATIO_RATIO_ALREADY_EXIST'
,
151
array
(
'#RATIO#'
=>
$arFields
[
'RATIO'
])
152
));
153
return
false
;
154
}
155
156
$result
= Catalog\MeasureRatioTable::update($id,
$arFields
);
157
if
(
$result
->isSuccess())
158
return
$id;
159
160
$errorList =
$result
->getErrorMessages();
161
if
(!empty($errorList))
162
$APPLICATION
->ThrowException(implode(
', '
, $errorList));
163
unset($errorList,
$result
);
164
return
false
;
165
}
166
177
public
static
function
delete
($id)
178
{
179
$id = (int)$id;
180
if
($id <= 0)
181
return
false
;
182
183
$result
= Catalog\MeasureRatioTable::delete($id);
184
if
(
$result
->isSuccess())
185
return
true
;
186
188
global
$APPLICATION
;
189
$errorList =
$result
->getErrorMessages();
190
if
(!empty($errorList))
191
$APPLICATION
->ThrowException(implode(
', '
, $errorList));
192
unset($errorList,
$result
);
193
return
false
;
194
}
195
}
CATALOG_VALUE_EPSILON
const CATALOG_VALUE_EPSILON
Определения
include.php:108
$APPLICATION
global $APPLICATION
Определения
include.php:80
Bitrix\Main\Localization\Loc
Определения
loc.php:12
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Определения
loc.php:30
CCatalogMeasureRatioAll
Определения
measure_ratio.php:7
CCatalogMeasureRatioAll\update
static update($id, $arFields)
Определения
measure_ratio.php:132
CCatalogMeasureRatioAll\checkFields
static checkFields($action, &$arFields)
Определения
measure_ratio.php:10
CCatalogMeasureRatioAll\$whiteList
static $whiteList
Определения
measure_ratio.php:8
CCatalogMeasureRatioAll\add
static add($arFields)
Определения
measure_ratio.php:95
$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
Bitrix\Catalog
$action
$action
Определения
file_dialog.php:21
bitrix
modules
catalog
general
measure_ratio.php
Создано системой
1.14.0