1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
productpropertyfeature.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Controller;
4
5use Bitrix\Catalog\Product\PropertyCatalogFeature;
6use Bitrix\Iblock\PropertyFeatureTable;
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 public function getAvailableFeaturesByPropertyAction(int $propertyId): ?array
30 {
31 $checkPropertyResult = $this->checkProperty($propertyId);
32 if (!$checkPropertyResult->isSuccess())
33 {
34 $this->addErrors($checkPropertyResult->getErrors());
35
36 return null;
37 }
38
39 $property = $this->getPropertyById($propertyId);
40 if (!$property)
41 {
42 $this->addError($this->getErrorEntityNotExists());
43
44 return null;
45 }
46
47 return [
48 'FEATURES' => PropertyCatalogFeature::getPropertyFeatureList($property),
49 ];
50 }
51
56 public function addAction(array $fields): ?array
57 {
58 $checkFieldsResult = $this->checkFieldsBeforeModify($fields);
59 if (!$checkFieldsResult->isSuccess())
60 {
61 $this->addErrors($checkFieldsResult->getErrors());
62 return null;
63 }
64
65 $propertyId = (int)$fields['PROPERTY_ID'];
66 unset($fields['PROPERTY_ID']);
67
68 $addResult = PropertyCatalogFeature::addFeatures($propertyId, [$fields]);
69 if (!$addResult->isSuccess())
70 {
71 $this->addErrors($addResult->getErrors());
72 return null;
73 }
74
75 $propertyFeatureId = current($addResult->getData());
76 return [$this->getServiceItemName() => $this->get($propertyFeatureId)];
77 }
78
83
88
94 public function updateAction(int $id, array $fields): ?array
95 {
96 $existsResult = $this->exists($id);
97 if (!$existsResult->isSuccess())
98 {
99 $this->addErrors($existsResult->getErrors());
100 return null;
101 }
102
103 $checkFieldsResult = $this->checkFieldsBeforeModify($fields);
104 if (!$checkFieldsResult->isSuccess())
105 {
106 $this->addErrors($checkFieldsResult->getErrors());
107 return null;
108 }
109
110 $propertyId = (int)$fields['PROPERTY_ID'];
111 unset($fields['PROPERTY_ID']);
112 $updateResult = PropertyCatalogFeature::updateFeatures($propertyId, [$fields]);
113 if (!$updateResult)
114 {
115 $this->addErrors($updateResult->getErrors());
116 return null;
117 }
118
119 return [$this->getServiceItemName() => $this->get($id)];
120 }
121
122 // endregion
123
127 protected function get($id)
128 {
130 'select' => ['*', 'IBLOCK_ID' => 'PROPERTY.IBLOCK_ID'],
131 'filter' => ['=ID' => $id],
132 ]);
133 }
134
138 protected function exists($id)
139 {
140 $result = new Result();
141 $propertyFeature = $this->get($id);
142 if (!$propertyFeature || !$this->isIblockCatalog((int)$propertyFeature['IBLOCK_ID']))
143 {
144 $result->addError($this->getErrorEntityNotExists());
145 }
146
147 return $result;
148 }
149
153 protected function getEntityTable()
154 {
155 return PropertyFeatureTable::class;
156 }
157
161 protected function checkPermissionEntity($name, $arguments = [])
162 {
163 if ($name === 'getavailablefeaturesbyproperty')
164 {
165 return $this->checkReadPermissionEntity();
166 }
167
168 return parent::checkPermissionEntity($name);
169 }
170
177 {
178 $params['filter']['PROPERTY.IBLOCK_ID'] = $this->getCatalogIds();
179
180 return $params;
181 }
182}
getAvailableFeaturesByPropertyAction(int $propertyId)
Определения productpropertyfeature.php:29
static getRow(array $parameters)
Определения datamanager.php:398
</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
$name
Определения menu_edit.php:35
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