1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Property.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\v2\Property;
4
5use Bitrix\Catalog\v2\BaseEntity;
6use Bitrix\Catalog\v2\Fields\FieldStorage;
7use Bitrix\Catalog\v2\HasSettingsTrait;
8use Bitrix\Catalog\v2\PropertyValue\HasPropertyValueCollection;
9use Bitrix\Catalog\v2\PropertyValue\PropertyValueCollection;
10use Bitrix\Catalog\v2\PropertyFeature\PropertyFeatureRepositoryContract;
11use Bitrix\Catalog\v2\PropertyFeature\PropertyFeatureCollection;
12use Bitrix\Catalog\v2\PropertyFeature\PropertyFeature;
13use Bitrix\Iblock;
14use Bitrix\Main\NotSupportedException;
15use Bitrix\Main\Result;
16
25class Property extends BaseEntity implements HasPropertyValueCollection
26{
28
35
36 public function __construct(
37 PropertyRepositoryContract $productRepository,
39 )
40 {
41 parent::__construct($productRepository);
42 $this->settings = new FieldStorage();
43 $this->propertyFeatureRepository = $propertyFeatureRepository;
44 }
45
47 {
48 return $this->propertyValueCollection;
49 }
50
52 {
53 $propertyValueCollection->setParent($this);
54
55 $this->propertyValueCollection = $propertyValueCollection;
56
57 return $this;
58 }
59
64 {
65 if ($this->propertyFeatureCollection === null)
66 {
67 // ToDo make lazy load like sku collection with iterator callback?
69 }
70
71 return $this->propertyFeatureCollection;
72 }
73
78 {
79 return $this->propertyFeatureRepository->getCollectionByParent($this);
80 }
81
83 {
84 $propertyFeatureCollection->setParent($this);
85
86 $this->propertyFeatureCollection = $propertyFeatureCollection;
87
88 return $this;
89 }
90
91 public function getId(): ?int
92 {
93 return (int)$this->getSetting('ID') ?: null;
94 }
95
96 public function setId(int $id): BaseEntity
97 {
98 throw new NotSupportedException('Property ID can\'t be modified.');
99 }
100
101 public function getCode(): string
102 {
103 return (string)$this->getSetting('CODE');
104 }
105
106 public function getName()
107 {
108 return $this->getSetting('NAME');
109 }
110
111 public function getDefaultValue()
112 {
113 $defaultValue = $this->getSetting('DEFAULT_VALUE');
114
115 if (
116 !empty($defaultValue)
117 && $this->getPropertyType() === 'S'
118 && $this->getUserType() === 'HTML'
119 )
120 {
122 ? unserialize($defaultValue, ['allowed_classes' => false])
123 : null;
124 }
125
126 return $defaultValue;
127 }
128
129 public function getPropertyType()
130 {
131 return $this->getSetting('PROPERTY_TYPE');
132 }
133
134 public function getUserType()
135 {
136 return $this->getSetting('USER_TYPE');
137 }
138
139 public function getListType()
140 {
141 return $this->getSetting('LIST_TYPE');
142 }
143
144 public function isRequired(): bool
145 {
146 return $this->getSetting('IS_REQUIRED') === 'Y';
147 }
148
149 public function isMultiple(): bool
150 {
151 return $this->getSetting('MULTIPLE') === 'Y';
152 }
153
154 public function isActive(): bool
155 {
156 return $this->getSetting('ACTIVE') === 'Y';
157 }
158
159 public function isPublic(): bool
160 {
161 $featureCollection = $this->getPropertyFeatureCollection();
162 $detailFeature = $featureCollection->findByFeatureId(Iblock\Model\PropertyFeature::FEATURE_ID_DETAIL_PAGE_SHOW);
163 if (!$detailFeature || !$detailFeature->isEnabled())
164 {
165 return false;
166 }
167
168 $listFeature = $featureCollection->findByFeatureId(Iblock\Model\PropertyFeature::FEATURE_ID_LIST_PAGE_SHOW);
169 if (!$listFeature || !$listFeature->isEnabled())
170 {
171 return false;
172 }
173
174 return true;
175 }
176
177 public function isFileType(): bool
178 {
179 return (
180 $this->getPropertyType() === 'F'
181 || $this->getUserType() === 'FileMan'
182 || $this->getUserType() === 'DiskFile'
183 );
184 }
185
186 public function saveInternal(): Result
187 {
188 return new Result();
189 }
190
191 public function deleteInternal(): Result
192 {
193 return new Result();
194 }
195
196 // ToDo rethink PropertyValueCollection saving and clearing
198 {
199 parent::clearChangedFields();
200
201 $this->getPropertyValueCollection()->clearChanged();
202
203 return $this;
204 }
205}
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения options.php:32
setPropertyValueCollection(PropertyValueCollection $propertyValueCollection)
Определения Property.php:51
getPropertyFeatureCollection()
Определения Property.php:63
__construct(PropertyRepositoryContract $productRepository, PropertyFeatureRepositoryContract $propertyFeatureRepository)
Определения Property.php:36
loadPropertyFeatureCollection()
Определения Property.php:77
setPropertyFeatureCollection(PropertyFeatureCollection $propertyFeatureCollection)
Определения Property.php:82
CheckSerializedData($str, $max_depth=200)
Определения tools.php:4949
getSetting(string $name)
Определения HasSettingsTrait.php:37
trait HasSettingsTrait
Определения HasSettingsTrait.php:8