1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
pricetype.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Main\Error;
6use Bitrix\Main\Result;
7use Bitrix\Rest\Event\EventBindInterface;
8use Bitrix\Rest\RestException;
9
10final class PriceType 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 const EVENT_ON_ADD = 'OnGroupAdd';
18 const EVENT_ON_UPDATE = 'OnGroupUpdate';
19 const EVENT_ON_DELETE = 'OnGroupDelete';
20
21 private const USER_GROUP_ADMINS = 1;
22 private const USER_GROUP_ALL_USERS = 2;
23
24 //region Actions
25
30 public function addAction(array $fields): ?array
31 {
33 $application->ResetException();
34
35 $fields['USER_GROUP'] = $fields['USER_GROUP_BUY'] = [self::USER_GROUP_ADMINS, self::USER_GROUP_ALL_USERS];
36
37 $addResult = \CCatalogGroup::Add($fields);
38 if (!$addResult)
39 {
40 if ($application->GetException())
41 {
42 $this->addError(new Error($application->GetException()->GetString()));
43 }
44 else
45 {
46 $this->addError(new Error('Error adding price type'));
47 }
48 return null;
49 }
50
51 return [$this->getServiceItemName() => $this->get($addResult)];
52 }
53
59 public function updateAction(int $id, array $fields): ?array
60 {
61 $existsResult = $this->exists($id);
62 if (!$existsResult->isSuccess())
63 {
64 $this->addErrors($existsResult->getErrors());
65 return null;
66 }
67
69 $application->ResetException();
70
71 $updateResult = \CCatalogGroup::Update($id, $fields);
72 if (!$updateResult)
73 {
74 if ($application->GetException())
75 {
76 $this->addError(new Error($application->GetException()->GetString()));
77 }
78 else
79 {
80 $this->addError(new Error('Error updating price type'));
81 }
82 return null;
83 }
84
85 return [$this->getServiceItemName() => $this->get($id)];
86 }
87
92 public function deleteAction(int $id): ?bool
93 {
94 $existsResult = $this->exists($id);
95 if (!$existsResult->isSuccess())
96 {
97 $this->addErrors($existsResult->getErrors());
98 return null;
99 }
100
102 $application->ResetException();
103
104 $deleteResult = \CCatalogGroup::Delete($id);
105 if (!$deleteResult)
106 {
107 if ($application->GetException())
108 {
109 $this->addError(new Error($application->GetException()->GetString()));
110 }
111 else
112 {
113 $this->addError(new Error('Error deleting price type'));
114 }
115 return null;
116 }
117
118 return true;
119 }
120
124 public function getFieldsAction(): array
125 {
126 return [$this->getServiceItemName() => $this->getViewFields()];
127 }
128
133
138
139 protected function getErrorCodeEntityNotExists(): string
140 {
142 }
143 //endregion
144
148 protected function getEntityTable()
149 {
150 return new \Bitrix\Catalog\GroupTable();
151 }
152
153 // rest-event region
154 protected static function getBindings(): array
155 {
156 $entity = (new self())->getEntity();
157
158 return [
159 self::EVENT_ON_ADD => $entity->getModule().'.price.type.on.add',
160 self::EVENT_ON_UPDATE => $entity->getModule().'.price.type.on.update',
161 self::EVENT_ON_DELETE => $entity->getModule().'.price.type.on.delete',
162 ];
163 }
164
168 public static function getCallbackRestEvent(): array
169 {
170 return [self::class, 'processItemEvent'];
171 }
172
178 public static function processItemEvent(array $params, array $handler): array
179 {
180 $id = $params[0] ?? null;
181 if (!$id)
182 {
183 throw new RestException('id not found trying to process event');
184 }
185
186 return [
187 'FIELDS' => [
188 'ID' => $id,
189 ],
190 ];
191 }
192 // endregion
193}
static getApplication()
Определения controller.php:56
const PRICE_TYPE_ENTITY_NOT_EXISTS
Определения errorcode.php:29
static getCallbackRestEvent()
Определения pricetype.php:168
addAction(array $fields)
Определения pricetype.php:30
static getBindings()
Определения pricetype.php:154
deleteAction(int $id)
Определения pricetype.php:92
updateAction(int $id, array $fields)
Определения pricetype.php:59
static processItemEvent(array $params, array $handler)
Определения pricetype.php:178
Определения error.php:15
static Delete($ID)
Определения cataloggroup.php:163
static Add($arFields)
Определения cataloggroup.php:9
static Update($ID, $arFields)
Определения cataloggroup.php:82
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$entity
$application
Определения bitrix.php:23
exists($id)
Определения checkexists.php:30
trait CheckExists
Определения checkexists.php:8
trait GetAction
Определения getaction.php:8
trait ListAction
Определения listaction.php:9
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$fields
Определения yandex_run.php:501