Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
roundingrule.php
1
<?php
2
3
4
namespace
Bitrix\Catalog\Controller
;
5
6
7
use
Bitrix\Catalog\RoundingTable
;
8
use
Bitrix\Main\Engine\Response\DataType\Page
;
9
use
Bitrix\Main\Error
;
10
use
Bitrix\Main\Result
;
11
use
Bitrix\Main\UI\PageNavigation
;
12
use
Bitrix\Rest\Event\EventBindInterface
;
13
14
final
class
RoundingRule
extends
Controller
implements
EventBindInterface
15
{
16
use PriceTypeRights;
17
18
//region Actions
19
24
public
function
addAction
(array $fields): ?array
25
{
26
$checkFieldsResult = $this->checkFields($fields);
27
if
(!$checkFieldsResult->isSuccess())
28
{
29
$this->addErrors($checkFieldsResult->getErrors());
30
return
null
;
31
}
32
33
$addResult =
RoundingTable::add
($fields);
34
if
(!$addResult->isSuccess())
35
{
36
$this->addErrors($addResult->getErrors());
37
return
null
;
38
}
39
40
return
[
'ROUNDING_RULE'
=> $this->
get
($addResult->getId())];
41
}
42
48
public
function
updateAction
(
int
$id, array $fields): ?array
49
{
50
$existsResult = $this->
exists
($id);
51
if
(!$existsResult->isSuccess())
52
{
53
$this->addErrors($existsResult->getErrors());
54
return
null
;
55
}
56
57
$checkFieldsResult = $this->checkFields($fields);
58
if
(!$checkFieldsResult->isSuccess())
59
{
60
$this->addErrors($checkFieldsResult->getErrors());
61
return
null
;
62
}
63
64
$updateResult =
RoundingTable::update
($id, $fields);
65
if
(!$updateResult)
66
{
67
$this->addErrors($updateResult->getErrors());
68
return
null
;
69
}
70
71
return
[
'ROUNDING_RULE'
=> $this->
get
($id)];
72
}
73
78
public
function
deleteAction
(
int
$id): ?bool
79
{
80
$existsResult = $this->
exists
($id);
81
if
(!$existsResult->isSuccess())
82
{
83
$this->addErrors($existsResult->getErrors());
84
return
null
;
85
}
86
87
$deleteResult =
RoundingTable::delete
($id);
88
if
(!$deleteResult)
89
{
90
$this->addErrors($deleteResult->getErrors());
91
return
null
;
92
}
93
94
return
true
;
95
}
96
100
public
function
getFieldsAction
(): array
101
{
102
return
[
'ROUNDING_RULE'
=> $this->
getViewFields
()];
103
}
104
112
public
function
listAction
(
PageNavigation
$pageNavigation, array $select = [], array $filter = [], array $order = []):
Page
113
{
114
return
new
Page
(
115
'ROUNDING_RULES'
,
116
$this->getList($select, $filter, $order, $pageNavigation),
117
$this->count($filter)
118
);
119
}
120
125
public
function
getAction
($id): ?array
126
{
127
$r = $this->
exists
($id);
128
if
($r->isSuccess())
129
{
130
return
[
'ROUNDING_RULE'
=> $this->
get
($id)];
131
}
132
else
133
{
134
$this->addErrors($r->getErrors());
135
return
null
;
136
}
137
}
138
//endregion
139
143
protected
function
exists
($id)
144
{
145
$r =
new
Result
();
146
if
(isset($this->
get
($id)[
'ID'
]) ==
false
)
147
{
148
$r->addError(
new
Error
(
'Rounding does not exist'
));
149
}
150
151
return
$r;
152
}
153
157
protected
function
getEntityTable
()
158
{
159
return
new
RoundingTable
();
160
}
161
166
private
function
checkFields(array $fields):
Result
167
{
168
$result =
new
Result
();
169
170
if
(array_key_exists(
'ROUND_TYPE'
, $fields))
171
{
172
$roundTypes =
RoundingTable::getRoundTypes
();
173
if
(!in_array($fields[
'ROUND_TYPE'
], $roundTypes))
174
{
175
$result->addError(
176
new
Error
(
177
'Invalid rounding type provided. The available values are: '
178
. implode(
', '
, $roundTypes)
179
)
180
);
181
}
182
unset($roundTypes);
183
}
184
185
if
(array_key_exists(
'ROUND_PRECISION'
, $fields))
186
{
187
$precisionList =
RoundingTable::getPresetRoundingValues
();
188
if
(!in_array($fields[
'ROUND_PRECISION'
], $precisionList))
189
{
190
$result->addError(
191
new
Error(
192
'Invalid rounding precision provided. The available values are: '
193
. implode(
', '
, $precisionList)
194
)
195
);
196
}
197
unset($precisionList);
198
}
199
200
return
$result;
201
}
202
}
Bitrix\Catalog\Controller\Controller\getViewFields
getViewFields()
Definition
controller.php:95
Bitrix\Catalog\Controller\RoundingRule
Definition
roundingrule.php:15
Bitrix\Catalog\Controller\RoundingRule\exists
exists($id)
Definition
roundingrule.php:143
Bitrix\Catalog\Controller\RoundingRule\addAction
addAction(array $fields)
Definition
roundingrule.php:24
Bitrix\Catalog\Controller\RoundingRule\getEntityTable
getEntityTable()
Definition
roundingrule.php:157
Bitrix\Catalog\Controller\RoundingRule\getFieldsAction
getFieldsAction()
Definition
roundingrule.php:100
Bitrix\Catalog\Controller\RoundingRule\deleteAction
deleteAction(int $id)
Definition
roundingrule.php:78
Bitrix\Catalog\Controller\RoundingRule\updateAction
updateAction(int $id, array $fields)
Definition
roundingrule.php:48
Bitrix\Catalog\Controller\RoundingRule\listAction
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])
Definition
roundingrule.php:112
Bitrix\Catalog\Controller\RoundingRule\getAction
getAction($id)
Definition
roundingrule.php:125
Bitrix\Catalog\RoundingTable
Definition
rounding.php:50
Bitrix\Catalog\RoundingTable\getRoundTypes
static getRoundTypes(bool $full=false)
Definition
rounding.php:443
Bitrix\Catalog\RoundingTable\getPresetRoundingValues
static getPresetRoundingValues()
Definition
rounding.php:466
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Engine\Response\DataType\Page
Definition
page.php:8
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Definition
datamanager.php:1632
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Definition
datamanager.php:874
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Definition
datamanager.php:1246
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\UI\PageNavigation
Definition
pagenavigation.php:27
Bitrix\Rest\Event\EventBindInterface
Definition
eventbindinterface.php:12
Bitrix\Catalog\Controller
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
modules
catalog
lib
controller
roundingrule.php
Создано системой
1.10.0