22 private array $skuProducts;
23 private array $skuTree;
34 parent::__construct([ $columnsId ], $settings);
38 $this->preloadResources();
43 foreach ($rowList as $index => $rowItem)
45 $type = $rowItem[
'data'][
'ROW_TYPE'] ??
null;
53 if ($type !== RowType::ELEMENT || $this->
getSettings()->isExcelMode())
55 $rowList[$index][
'columns'][$columnId] = $rowItem[
'columns'][
'NAME'] ?? $rowItem[
'data'][
'NAME'];
59 $rowList[$index][
'columns'][$columnId] = $this->getProductSelectorHtml($rowList[$index][
'data']);
67 private function initSkuTree(): void
71 if (empty($this->skuProducts))
77 $skuTree = ServiceContainer::make(
'sku.tree', [
85 $this->skuTree = $skuTree->loadJsonOffers($this->skuProducts);
98 private function preloadResources(): void
100 Asset::getInstance()->addJs(
'/bitrix/components/bitrix/catalog.grid.product.field/templates/.default/script.js');
101 Asset::getInstance()->addCss(
'/bitrix/components/bitrix/catalog.grid.product.field/templates/.default/style.css');
104 private function getProductSelectorHtml(array $row): string
112 $productId = (int)$row[
'ID'];
113 $skuId = $this->getProductSkuId($productId);
115 $productFields = array_merge($row, [
116 'IBLOCK_ID' => $this->
getSettings()->getIblockId(),
117 'SKU_IBLOCK_ID' => $this->
getSettings()->getOffersIblockId(),
121 $urlBuilder = $this->
getSettings()->getUrlBuilder();
124 $APPLICATION->IncludeComponent(
125 'bitrix:catalog.grid.product.field',
130 'ROW_ID' => RowType::ELEMENT . $productId,
131 'ROW_ID_MASK' =>
'E#ID#',
132 'PRODUCT_FIELDS' => $productFields,
133 'ENABLE_IMAGE_INPUT' =>
false,
134 'ENABLE_CHANGES_RENDERING' =>
false,
135 'USE_SKU_TREE' =>
true,
136 'BUILDER_CONTEXT' => isset($urlBuilder) ? $urlBuilder->getId() : null,
137 'SKU_TREE' => $this->skuTree[$productId][$skuId] ?? [],
141 return ob_get_clean();
144 private function getProductSkuId(
int $productId): ?int
146 return $this->skuProducts[$productId] ??
null;