Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Property.php
1<?php
2
4
7use Bitrix\Catalog\v2\HasSettingsTrait;
16
26{
27 use HasSettingsTrait;
28
35
36 public function __construct(
37 PropertyRepositoryContract $productRepository,
38 PropertyFeatureRepositoryContract $propertyFeatureRepository
39 )
40 {
41 parent::__construct($productRepository);
42 $this->settings = new FieldStorage();
43 $this->propertyFeatureRepository = $propertyFeatureRepository;
44 }
45
47 {
48 return $this->propertyValueCollection;
49 }
50
51 public function setPropertyValueCollection(PropertyValueCollection $propertyValueCollection): self
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
82 public function setPropertyFeatureCollection(PropertyFeatureCollection $propertyFeatureCollection): self
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 {
121 $defaultValue = CheckSerializedData($defaultValue)
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}
setPropertyValueCollection(PropertyValueCollection $propertyValueCollection)
Definition Property.php:51
__construct(PropertyRepositoryContract $productRepository, PropertyFeatureRepositoryContract $propertyFeatureRepository)
Definition Property.php:36
setPropertyFeatureCollection(PropertyFeatureCollection $propertyFeatureCollection)
Definition Property.php:82
getSetting(string $name)