Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
skutree.php
1<?php
2
4
9
11{
12 public function configureActions()
13 {
14 return [
15 'getSku' => [
16 '+prefilters' => [
17 new ActionFilter\CloseSession(),
18 ],
19 '-prefilters' => [
20 ActionFilter\Authentication::class,
21 ],
22 ],
23 'getIblockProperties' => [
24 '-prefilters' => [
25 ActionFilter\Authentication::class,
26 ],
27 ],
28 ];
29 }
30 protected function getDefaultPreFilters()
31 {
32 return array_merge(
33 parent::getDefaultPreFilters(),
34 [
35 new ActionFilter\HttpMethod([ActionFilter\HttpMethod::METHOD_POST]),
36 new ActionFilter\Scope(ActionFilter\Scope::AJAX),
37 ]
38 );
39 }
40
41 public function getIblockPropertiesAction(int $iblockId): array
42 {
43 if ($iblockId <= 0)
44 {
45 return [];
46 }
47
48 $skuTree = ServiceContainer::make('sku.tree', ['iblockId' => $iblockId]);
49 if ($skuTree)
50 {
51 return $skuTree->getTreeProperties();
52 }
53
54 return [];
55 }
56
57 public function getSkuAction(int $skuId): array
58 {
59 $iterator = \CIBlockElement::GetList(
60 [],
61 [
62 'ID' => $skuId,
63 'ACTIVE' => 'Y',
64 'ACTIVE_DATE' => 'Y',
65 'CHECK_PERMISSIONS' => 'Y',
66 'MIN_PERMISSION' => 'R',
67 ],
68 false,
69 false,
70 ['ID', 'IBLOCK_ID']
71 );
72 $element = $iterator->Fetch();
73 if (!$element)
74 {
75 return [];
76 }
77 unset($iterator);
78
79 $skuRepository = ServiceContainer::getSkuRepository($element['IBLOCK_ID']);
80 if (!$skuRepository)
81 {
82 return [];
83 }
84
86 $sku = $skuRepository->getEntityById($skuId);
87
88 if (!$sku || $sku->isSimple())
89 {
90 return [];
91 }
92
93 $parentProduct = $sku->getParent();
94 if (!$parentProduct)
95 {
96 return [];
97 }
98
100 $skuTree = ServiceContainer::make('sku.tree', [
101 'iblockId' => $parentProduct->getIblockId(),
102 ]);
103
104 if (!$skuTree)
105 {
106 return [];
107 }
108
109 $productId = $parentProduct->getId();
110
111 $offers = $skuTree->loadWithSelectedOffers([
112 $productId => $skuId,
113 ]);
114
115 if ($offers[$productId][$skuId] && is_array($offers[$productId][$skuId]['OFFERS']))
116 {
117 foreach ($offers[$productId][$skuId]['OFFERS'] as $offer)
118 {
119 if ((int)$offer['ID'] === $skuId)
120 {
121 unset($offer['DISPLAY_PROPERTIES'], $offer['PROPERTIES']);
122 return $offer;
123 }
124 }
125 }
126
127 return [];
128 }
129}
getIblockPropertiesAction(int $iblockId)
Definition skutree.php:41