Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productpropertysection.php
1<?php
2
4
5use Bitrix\Catalog\Product\PropertyCatalogFeature;
13
15{
16 private const BLANK_SECTION = 0;
17
18 // region Actions
19
27 public function listAction(PageNavigation $pageNavigation, array $select = [], array $filter = [], array $order = []): Page
28 {
29 $filter['PROPERTY.IBLOCK_ID'] = $this->getCatalogIds();
30 $order = empty($order) ? ['IBLOCK_ID' => 'ASC'] : $order;
31
32 return new Page(
33 'PRODUCT_PROPERTY_SECTIONS',
34 $this->getList($select, $filter, $order, $pageNavigation),
35 $this->count($filter)
36 );
37 }
38
43 public function getAction(int $propertyId): ?array
44 {
45 $checkPropertyResult = $this->checkProperty($propertyId);
46 if (!$checkPropertyResult->isSuccess())
47 {
48 $this->addErrors($checkPropertyResult->getErrors());
49 return null;
50 }
51
52 return ['PRODUCT_PROPERTY_SECTION' => $this->get($propertyId)];
53 }
54
60 public function setAction(int $propertyId, array $fields): ?array
61 {
62 $checkPropertyResult = $this->checkProperty($propertyId);
63 if (!$checkPropertyResult->isSuccess())
64 {
65 $this->addErrors($checkPropertyResult->getErrors());
66 return null;
67 }
68
69 $property = $this->getPropertyById($propertyId);
70 $fields['IBLOCK_ID'] = $property['IBLOCK_ID'];
71
72 \CIBlockSectionPropertyLink::Set(self::BLANK_SECTION, $propertyId, $fields);
73
74 $result = $this->get($propertyId);
75 if (!$result)
76 {
77 $this->addError(new Error('Error setting section properties'));
78 return null;
79 }
80
81 return ['PRODUCT_PROPERTY_SECTION' => $this->get($propertyId)];
82 }
83
84 // endregion
85
89 protected function getEntityTable()
90 {
91 return SectionPropertyTable::class;
92 }
93
97 protected function checkPermissionEntity($name, $arguments = [])
98 {
99 if ($name === 'set')
100 {
101 return $this->checkModifyPermissionEntity();
102 }
103
104 return parent::checkPermissionEntity($name);
105 }
106
110 protected function get($id)
111 {
112 return SectionPropertyTable::getRow([
113 'filter' => ['=PROPERTY_ID' => $id],
114 'order' => ['IBLOCK_ID' => 'ASC'],
115 ]);
116 }
117}
listAction(PageNavigation $pageNavigation, array $select=[], array $filter=[], array $order=[])