32 private const EVENT_PREFIX =
'Bitrix\Catalog\Product\Entity::';
57 $this->
setIblockId($this->iblockInfo->getProductIblockId());
62 $userField = SystemField\ProductMapping::load();
63 if (!empty($userField))
65 $value = (!empty($userField[
'SETTINGS'][
'DEFAULT_VALUE']) && is_array($userField[
'SETTINGS'][
'DEFAULT_VALUE'])
66 ? $userField[
'SETTINGS'][
'DEFAULT_VALUE']
72 $className = SystemField\ProductMapping::getTypeId();
74 $list = $className::getIdByXmlId(
75 $userField[
'SETTINGS'][
'HLBLOCK_ID'],
78 if (isset($list[
SystemField\ProductMapping::MAP_LANDING]))
81 $list[SystemField\ProductMapping::MAP_LANDING],
87 $this->
setField($userField[
'FIELD_NAME'], $value);
98 if ($this->sectionCollection ===
null)
112 return $this->sectionRepository->getCollectionByProduct($this);
135 if ($this->skuCollection ===
null)
138 $this->skuRepository->getCollectionByProduct($this)
150 if ($this->skuCollection ===
null)
153 $this->skuRepository->loadEagerCollectionByProduct($this)
177 $isNew = $this->
isNew();
184 $result = parent::saveInternal();
185 if ($result->isSuccess())
189 $eventId = self::EVENT_PREFIX . ORM\Data\DataManager::EVENT_ON_AFTER_ADD;
193 $eventId = self::EVENT_PREFIX . ORM\Data\DataManager::EVENT_ON_AFTER_UPDATE;
196 $this->sendOnAfterEvents($eventId);
205 if ($result->isSuccess())
207 $this->sendOnAfterEvents(self::EVENT_PREFIX . ORM\Data\DataManager::EVENT_ON_AFTER_DELETE);
213 private function sendOnAfterEvents(
string $eventId): void
216 'id' => $this->
getId(),
221 case self::EVENT_PREFIX . ORM\Data\DataManager::EVENT_ON_AFTER_ADD:
222 case self::EVENT_PREFIX . ORM\Data\DataManager::EVENT_ON_AFTER_UPDATE:
223 $eventData[
'fields'] = $this->
getFields();
234 $eventData[
'fields'][
'PRICES'] = $item->getPriceCollection()->toArray();
240 $event =
new Event(
'catalog', $eventId, $eventData);
246 if ($name ===
'NAME')
248 $productName = $this->
getName();
252 if ($sku->getName() === $productName)
254 $sku->setName($value);
259 return parent::setField($name, $value);