1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
roundingrule.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\RoundingTable;
6use Bitrix\Main\Error;
7use Bitrix\Main\Result;
8use Bitrix\Rest\Event\EventBindInterface;
9
10final 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 {
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 {
166 }
167}
const ROUNDING_RULE_ENTITY_NOT_EXISTS
Определения errorcode.php:26
addAction(array $fields)
Определения roundingrule.php:23
updateAction(int $id, array $fields)
Определения roundingrule.php:47
static getRoundTypes(bool $full=false)
Определения rounding.php:443
static getPresetRoundingValues()
Определения rounding.php:466
Определения error.php:15
static delete($primary)
Определения datamanager.php:1644
static add(array $data)
Определения datamanager.php:877
static update($primary, array $data)
Определения datamanager.php:1256
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
exists($id)
Определения checkexists.php:30
trait CheckExists
Определения checkexists.php:8
trait GetAction
Определения getaction.php:8
trait ListAction
Определения listaction.php:9
$fields
Определения yandex_run.php:501