1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
productlist.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Component;
4
5use Bitrix\Iblock\Url\AdminPage\BuilderManager;
6use Bitrix\Main;
7use Bitrix\Catalog\v2\IoC\ServiceContainer;
8
9abstract class ProductList extends \CBitrixComponent
10{
11 protected $measures = [];
12
13 protected function loadCatalog(array $skuIds): array
14 {
16
17 $repositoryFacade = ServiceContainer::getRepositoryFacade();
18 if (!$repositoryFacade)
19 {
20 return [];
21 }
22
23 $productInfo = [];
24 $productSkuIblockMap = [];
25 foreach ($skuIds as $skuId)
26 {
27 $sku = $repositoryFacade->loadVariation($skuId);
28 if (!$sku)
29 {
30 continue;
31 }
32
34 $product = $sku->getParent();
35 if (!$product)
36 {
37 continue;
38 }
39
40 $fields = $sku->getFields();
41 $fields['PRODUCT_ID'] = $product->getId();
42 $fields['SKU_ID'] = $skuId;
43 $fields['OFFERS_IBLOCK_ID'] = 0;
44 $fields['SKU_TREE'] = [];
45 $fields['DETAIL_URL'] = $this->getElementDetailUrl($product->getIblockId(), $product->getId());
46 $fields['TYPE'] = (int)$fields['TYPE'];
47
48 $measure = $this->measures[$sku->getField('MEASURE')] ?? null;
49 if (!$measure)
50 {
51 $measure = $this->getDefaultMeasure();
52 }
53
54 $fields['MEASURE_CODE'] = $measure['CODE'];
55 $fields['MEASURE_NAME'] = $measure['SYMBOL'];
56
57 if (!$product->isSimple())
58 {
59 $fields['OFFERS_IBLOCK_ID'] = $fields['IBLOCK_ID'];
60 $fields['IBLOCK_ID'] = $product->getIblockId();
61 $productSkuIblockMap[$product->getIblockId()] = $productSkuIblockMap[$product->getIblockId()] ?? [];
62 $productSkuIblockMap[$product->getIblockId()][$product->getId()][] = $sku->getId();
63 }
64
65 $productInfo[$skuId] = [
66 'SKU' => $sku,
67 'FIELDS' => $fields,
68 ];
69 }
70
71 if ($productSkuIblockMap)
72 {
73 foreach ($productSkuIblockMap as $iblockId => $productMap)
74 {
75 $skuTree = ServiceContainer::make('sku.tree', ['iblockId' => $iblockId]);
76 if ($skuTree)
77 {
78 $skuTreeItems = $skuTree->loadJsonOffers($productMap);
79 foreach ($skuTreeItems as $offers)
80 {
81 foreach ($offers as $skuId => $skuTreeItem)
82 {
83 if (isset($productInfo[$skuId]['FIELDS']))
84 {
85 $productInfo[$skuId]['FIELDS']['SKU_TREE'] = $skuTreeItem;
86 }
87 }
88 }
89 }
90 }
91 }
92
93 return $productInfo;
94 }
95
96 protected function getElementDetailUrl(int $iblockId, int $skuId = 0): string
97 {
98 $urlBuilder = BuilderManager::getInstance()->getBuilder($this->arParams['BUILDER_CONTEXT']);
99 if (!$urlBuilder)
100 {
101 return '';
102 }
103
104 $urlBuilder->setIblockId($iblockId);
105 return $urlBuilder->getElementDetailUrl($skuId);
106 }
107
108 protected function loadMeasures(): void
109 {
110 $measureResult = \CCatalogMeasure::getList(
111 ['CODE' => 'ASC'],
112 [],
113 false,
114 [],
115 ['CODE', 'SYMBOL_RUS', 'SYMBOL_INTL', 'IS_DEFAULT', 'ID']
116 );
117
118 $this->measures = [];
119 while ($measureFields = $measureResult->Fetch())
120 {
121 $measureItem = [
122 'ID' => $measureFields['ID'],
123 'CODE' => $measureFields['CODE'],
124 'IS_DEFAULT' => $measureFields['IS_DEFAULT'],
125 'SYMBOL' => $measureFields['SYMBOL_RUS'] ?? $measureFields['SYMBOL_INTL'],
126 ];
127
128 $this->measures[$measureFields['ID']] = $measureItem;
129 }
130 }
131
135 protected function getDefaultMeasure(): array
136 {
137 return \CCatalogMeasure::getDefaultMeasure(true);
138 }
139}
getElementDetailUrl(int $iblockId, int $skuId=0)
Определения productlist.php:96
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$iblockId
Определения iblock_catalog_edit.php:30
$fields
Определения yandex_run.php:501