1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
productpropertyenum.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Iblock\PropertyEnumerationTable;
6use Bitrix\Iblock\PropertyTable;
7use Bitrix\Main\Error;
8use Bitrix\Main\Result;
9
11{
12 use ListAction; // default listAction realization
13 use GetAction; // default getAction realization
14
15 // region Actions
16
20 public function getFieldsAction(): array
21 {
22 return [$this->getServiceItemName() => $this->getViewFields()];
23 }
24
29
34
35 public function addAction(array $fields): ?array
36 {
37 $checkFieldsResult = $this->checkFieldsBeforeModify($fields);
38 if (!$checkFieldsResult->isSuccess())
39 {
40 $this->addErrors($checkFieldsResult->getErrors());
41 return null;
42 }
43
44 $property = $this->getPropertyById($fields['PROPERTY_ID']);
45 if (!$property)
46 {
47 $this->addError($this->getErrorEntityNotExists());
48
49 return null;
50 }
51
52 $propertyType = $property['PROPERTY_TYPE'];
53 if ($propertyType !== PropertyTable::TYPE_LIST)
54 {
55 $this->addError(new Error('Only list properties are supported'));
56
57 return null;
58 }
59
61 $application->ResetException();
62
63 $addResult = PropertyEnumerationTable::add($fields);
64 if (!$addResult->isSuccess())
65 {
66 $this->addErrors($addResult->getErrors());
67
68 return null;
69 }
70
71 return [
72 $this->getServiceItemName() => $this->get($addResult->getId()),
73 ];
74 }
75
81 public function updateAction(int $id, array $fields): ?array
82 {
83 $existsResult = $this->exists($id);
84 if (!$existsResult->isSuccess())
85 {
86 $this->addErrors($existsResult->getErrors());
87 return null;
88 }
89
90 $checkFieldsResult = $this->checkFieldsBeforeModify($fields);
91 if (!$checkFieldsResult->isSuccess())
92 {
93 $this->addErrors($checkFieldsResult->getErrors());
94 return null;
95 }
96
97 $propertyId = $this->get($id)['PROPERTY_ID'];
98 $updateResult = PropertyEnumerationTable::update([
99 'ID' => $id,
100 'PROPERTY_ID' => $propertyId,
101 ], $fields);
102 if (!$updateResult)
103 {
104 $this->addErrors($updateResult->getErrors());
105 return null;
106 }
107
108 return [$this->getServiceItemName() => $this->get($id)];
109 }
110
115 public function deleteAction(int $id): ?bool
116 {
117 $existsResult = $this->exists($id);
118 if (!$existsResult->isSuccess())
119 {
120 $this->addErrors($existsResult->getErrors());
121 return null;
122 }
123
124 $propertyId = $this->get($id)['PROPERTY_ID'];
125 $deleteResult = PropertyEnumerationTable::delete([
126 'ID' => $id,
127 'PROPERTY_ID' => $propertyId,
128 ]);
129
130 if (!$deleteResult)
131 {
132 $this->addErrors($deleteResult->getErrors());
133 return null;
134 }
135
136 return $deleteResult->isSuccess();
137 }
138
139 // endregion
140
144 protected function get($id)
145 {
146 return PropertyEnumerationTable::getRow([
147 'select' => ['*', 'IBLOCK_ID' => 'PROPERTY.IBLOCK_ID'],
148 'filter' => ['=ID' => $id],
149 ]);
150 }
151
155 protected function exists($id)
156 {
157 $result = new Result();
158 $propertyEnum = $this->get($id);
159 if (!$propertyEnum || !$this->isIblockCatalog((int)$propertyEnum['IBLOCK_ID']))
160 {
161 $result->addError($this->getErrorEntityNotExists());
162 }
163
164 return $result;
165 }
166
170 protected function getEntityTable()
171 {
172 return PropertyEnumerationTable::class;
173 }
174
181 {
182 $params['filter']['PROPERTY.IBLOCK_ID'] = $this->getCatalogIds();
183
184 return $params;
185 }
186}
static getApplication()
Определения controller.php:56
updateAction(int $id, array $fields)
Определения productpropertyenum.php:81
const TYPE_LIST
Определения propertytable.php:70
Определения error.php:15
</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
$application
Определения bitrix.php:23
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