1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
roundingrule.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Catalog\Controller;
4
5
use Bitrix\Catalog\RoundingTable;
6
use Bitrix\Main\Error;
7
use Bitrix\Main\Result;
8
use Bitrix\Rest\Event\EventBindInterface;
9
10
final
class
RoundingRule
extends
Controller
implements
EventBindInterface
11
{
12
use
ListAction
;
// default listAction realization
13
use
GetAction
;
// default getAction realization
14
use
CheckExists
;
// default implementation of existence check
15
use PriceTypeRights;
16
17
//region Actions
18
23
public
function
addAction
(
array
$fields
): ?
array
24
{
25
$checkFieldsResult = $this->checkFields(
$fields
);
26
if
(!$checkFieldsResult->isSuccess())
27
{
28
$this->addErrors($checkFieldsResult->getErrors());
29
return
null
;
30
}
31
32
$addResult =
RoundingTable::add
(
$fields
);
33
if
(!$addResult->isSuccess())
34
{
35
$this->addErrors($addResult->getErrors());
36
return
null
;
37
}
38
39
return
[$this->
getServiceItemName
() => $this->
get
($addResult->getId())];
40
}
41
47
public
function
updateAction
(
int
$id,
array
$fields
): ?
array
48
{
49
$existsResult = $this->
exists
($id);
50
if
(!$existsResult->isSuccess())
51
{
52
$this->addErrors($existsResult->getErrors());
53
return
null
;
54
}
55
56
$checkFieldsResult = $this->checkFields(
$fields
);
57
if
(!$checkFieldsResult->isSuccess())
58
{
59
$this->addErrors($checkFieldsResult->getErrors());
60
return
null
;
61
}
62
63
$updateResult =
RoundingTable::update
($id,
$fields
);
64
if
(!$updateResult)
65
{
66
$this->addErrors($updateResult->getErrors());
67
return
null
;
68
}
69
70
return
[$this->
getServiceItemName
() => $this->
get
($id)];
71
}
72
77
public
function
deleteAction
(
int
$id): ?bool
78
{
79
$existsResult = $this->
exists
($id);
80
if
(!$existsResult->isSuccess())
81
{
82
$this->addErrors($existsResult->getErrors());
83
return
null
;
84
}
85
86
$deleteResult =
RoundingTable::delete
($id);
87
if
(!$deleteResult)
88
{
89
$this->addErrors($deleteResult->getErrors());
90
return
null
;
91
}
92
93
return
true
;
94
}
95
99
public
function
getFieldsAction
():
array
100
{
101
return
[$this->
getServiceItemName
() => $this->
getViewFields
()];
102
}
103
108
113
117
protected
function
getEntityTable
()
118
{
119
return
new
RoundingTable
();
120
}
121
126
private
function
checkFields(
array
$fields
):
Result
127
{
128
$result
=
new
Result
();
129
130
if
(array_key_exists(
'ROUND_TYPE'
,
$fields
))
131
{
132
$roundTypes =
RoundingTable::getRoundTypes
();
133
if
(!in_array(
$fields
[
'ROUND_TYPE'
], $roundTypes))
134
{
135
$result
->addError(
136
new
Error
(
137
'Invalid rounding type provided. The available values are: '
138
. implode(
', '
, $roundTypes)
139
)
140
);
141
}
142
unset($roundTypes);
143
}
144
145
if
(array_key_exists(
'ROUND_PRECISION'
,
$fields
))
146
{
147
$precisionList =
RoundingTable::getPresetRoundingValues
();
148
if
(!in_array(
$fields
[
'ROUND_PRECISION'
], $precisionList))
149
{
150
$result
->addError(
151
new
Error(
152
'Invalid rounding precision provided. The available values are: '
153
. implode(
', '
, $precisionList)
154
)
155
);
156
}
157
unset($precisionList);
158
}
159
160
return
$result
;
161
}
162
163
protected
function
getErrorCodeEntityNotExists
(): string
164
{
165
return
ErrorCode::ROUNDING_RULE_ENTITY_NOT_EXISTS
;
166
}
167
}
Bitrix\Catalog\Controller\Controller\getServiceItemName
getServiceItemName()
Определения
controller.php:139
Bitrix\Catalog\Controller\Controller\getViewFields
getViewFields()
Определения
controller.php:107
Bitrix\Catalog\Controller\ErrorCode\ROUNDING_RULE_ENTITY_NOT_EXISTS
const ROUNDING_RULE_ENTITY_NOT_EXISTS
Определения
errorcode.php:26
Bitrix\Catalog\Controller\RoundingRule
Определения
roundingrule.php:11
Bitrix\Catalog\Controller\RoundingRule\getErrorCodeEntityNotExists
getErrorCodeEntityNotExists()
Определения
roundingrule.php:163
Bitrix\Catalog\Controller\RoundingRule\addAction
addAction(array $fields)
Определения
roundingrule.php:23
Bitrix\Catalog\Controller\RoundingRule\getEntityTable
getEntityTable()
Определения
roundingrule.php:117
Bitrix\Catalog\Controller\RoundingRule\getFieldsAction
getFieldsAction()
Определения
roundingrule.php:99
Bitrix\Catalog\Controller\RoundingRule\deleteAction
deleteAction(int $id)
Определения
roundingrule.php:77
Bitrix\Catalog\Controller\RoundingRule\updateAction
updateAction(int $id, array $fields)
Определения
roundingrule.php:47
Bitrix\Catalog\RoundingTable
Определения
rounding.php:50
Bitrix\Catalog\RoundingTable\getRoundTypes
static getRoundTypes(bool $full=false)
Определения
rounding.php:443
Bitrix\Catalog\RoundingTable\getPresetRoundingValues
static getPresetRoundingValues()
Определения
rounding.php:466
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\ORM\Data\DataManager\delete
static delete($primary)
Определения
datamanager.php:1644
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Определения
datamanager.php:877
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Определения
datamanager.php:1256
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\Rest\Event\EventBindInterface
Определения
eventbindinterface.php:12
Bitrix\Catalog\Controller
Bitrix\Catalog\Controller\exists
exists($id)
Определения
checkexists.php:30
Bitrix\Catalog\Controller\CheckExists
trait CheckExists
Определения
checkexists.php:8
Bitrix\Catalog\Controller\GetAction
trait GetAction
Определения
getaction.php:8
Bitrix\Catalog\Controller\ListAction
trait ListAction
Определения
listaction.php:9
Bitrix\Sale\Discount\Result
Определения
compatibleformat.php:2
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
catalog
lib
controller
roundingrule.php
Создано системой
1.14.0