7if (Loader::includeModule(
'iblock'))
11 public const TYPE_ID =
'CATALOG';
13 protected const TYPE_WEIGHT = 200;
15 public const PAGE_OFFER_DETAIL =
'offerDetail';
17 protected $catalog =
null;
19 protected $catalogType =
null;
21 protected $parents = [];
23 public function use(): bool
25 return (defined(
'CATALOG_PRODUCT') && parent::use());
28 public function setIblockId(
int $iblockId): void
30 if ($this->iblockId !== $iblockId)
32 parent::setIblockId($iblockId);
37 public function clearPreloadedUrlData(): void
42 public function getProductDetailUrl(
int $entityId, array $options = [],
string $additional =
''): string
44 if (empty($this->catalog))
48 if ($this->catalogType !== \CCatalogSku::TYPE_OFFERS)
50 return $this->getElementDetailUrl($entityId, $options, $additional);
55 $parentId = $this->getProductParent($entityId);
56 if (!empty($parentId))
58 $result = $this->fillUrlTemplate(
59 $this->getUrlTemplate(self::PAGE_OFFER_DETAIL),
60 $this->getOfferVariables($entityId, $parentId, $options, $additional)
68 protected function resetIblock(): void
70 parent::resetIblock();
71 $this->catalog =
null;
72 $this->catalogType =
null;
75 protected function setCatalog()
77 $this->catalog = \CCatalogSku::GetInfoByIBlock($this->iblockId);
78 if ($this->catalog ===
false)
80 $this->catalog =
null;
82 if (empty($this->catalog))
84 $this->catalogType =
null;
85 $this->setTemplateVariable(
'#PRODUCT_IBLOCK_ID#',
'');
86 $this->setTemplateVariable(
'#OFFER_IBLOCK_ID#',
'');
90 $this->catalogType = $this->catalog[
'CATALOG_TYPE'];
91 $productIblockId =
'';
93 switch ($this->catalogType)
95 case \CCatalogSku::TYPE_CATALOG:
96 $productIblockId = $this->catalog[
'IBLOCK_ID'];
98 case \CCatalogSku::TYPE_OFFERS:
99 case \CCatalogSku::TYPE_FULL:
100 case \CCatalogSku::TYPE_PRODUCT:
101 $productIblockId = $this->catalog[
'PRODUCT_IBLOCK_ID'];
102 $offerIblockId = $this->catalog[
'IBLOCK_ID'];
105 $this->setTemplateVariable(
'#PRODUCT_IBLOCK_ID#', $productIblockId);
106 $this->setTemplateVariable(
'#OFFER_IBLOCK_ID#', $offerIblockId);
107 unset($offerIblockId, $productIblockId);
111 protected function initUrlTemplates(): void
113 $this->urlTemplates[self::PAGE_SECTION_LIST] =
'#PATH_PREFIX#'
114 .($this->iblockListMixed ?
'cat_product_list.php' :
'cat_section_admin.php')
117 .
'#ADDITIONAL_PARAMETERS#';
118 $this->urlTemplates[self::PAGE_SECTION_DETAIL] =
'#PATH_PREFIX#'
119 .
'cat_section_edit.php'
122 .
'#ADDITIONAL_PARAMETERS#';
123 $this->urlTemplates[self::PAGE_SECTION_COPY] = $this->urlTemplates[self::PAGE_SECTION_DETAIL]
124 .$this->getCopyAction();
125 $this->urlTemplates[self::PAGE_SECTION_SAVE] =
'#PATH_PREFIX#'
126 .
'cat_section_edit.php'
128 .
'#ADDITIONAL_PARAMETERS#';
129 $this->urlTemplates[self::PAGE_SECTION_SEARCH] =
'/bitrix/tools/iblock/section_search.php'
131 .
'#ADDITIONAL_PARAMETERS#';
133 $this->urlTemplates[self::PAGE_ELEMENT_LIST] =
'#PATH_PREFIX#'
134 .($this->iblockListMixed ?
'cat_product_list.php' :
'cat_product_admin.php')
137 .
'#ADDITIONAL_PARAMETERS#';
138 $this->urlTemplates[self::PAGE_ELEMENT_DETAIL] =
'#PATH_PREFIX#'
139 .
'cat_product_edit.php'
142 .
'#ADDITIONAL_PARAMETERS#';
143 $this->urlTemplates[self::PAGE_ELEMENT_COPY] = $this->urlTemplates[self::PAGE_ELEMENT_DETAIL]
144 .$this->getCopyAction();
145 $this->urlTemplates[self::PAGE_ELEMENT_SAVE] =
'#PATH_PREFIX#'
146 .
'cat_product_edit.php'
148 .
'#ADDITIONAL_PARAMETERS#';
149 $this->urlTemplates[self::PAGE_ELEMENT_SEARCH] =
'/bitrix/tools/iblock/element_search.php'
151 .
'#ADDITIONAL_PARAMETERS#';
152 $this->urlTemplates[self::PAGE_OFFER_DETAIL] = $this->urlTemplates[self::PAGE_ELEMENT_DETAIL];
155 protected function preloadElementUrlData(array $elementIds): void
157 if ($this->catalogType !== \CCatalogSku::TYPE_OFFERS)
159 parent::preloadElementUrlData($elementIds);
164 foreach ($elementIds as $id)
166 if (!isset($this->parents[$id]))
168 $this->parents[$id] =
false;
175 $parents = \CCatalogSku::getProductList($load, $this->iblockId);
176 if (!empty($parents))
178 foreach ($parents as $id => $data)
180 $this->parents[$id] = $data[
'ID'];
190 protected function getProductParent(
int $entityId): ?int
192 if (!isset($this->parents[$entityId]))
194 $this->parents[$entityId] =
false;
195 $parents = \CCatalogSku::getProductList([$entityId], $this->iblockId);
196 if (!empty($parents) && isset($parents[$entityId]))
198 $this->parents[$entityId] = $parents[$entityId][
'ID'];
202 return (!empty($this->parents[$entityId]) ? $this->parents[$entityId] : null);
205 protected function getOfferVariables(
int $entityId,
int $productId, array $options = [],
string $additional =
''): array
207 $replaces = $this->getExtendedVariables($options, $additional);
208 $replaces[
'#PRODUCT_ID#'] = (string)$productId;
209 $replaces[
'#ENTITY_ID#'] = (string)$entityId;
210 $replaces[
'#ENTITY_FILTER#'] = $this->getEntityFilter($entityId);