76 $productIds = array_keys($productToOfferMap);
77 $products = $this->prepareProductsOfferTree($productIds);
80 foreach ($productToOfferMap as $productId => $offerMap)
82 if (!isset($products[$productId]))
87 $product =& $products[$productId];
90 foreach ((array)$offerMap as $offerId)
93 $offers[$offerId] = $product;
121 foreach ($offersMap as $productId => $offers)
123 $result[$productId] = $result[$productId] ?? [];
124 foreach ((array)$offers as $offerId => $offerData)
127 foreach ($offerData[
'OFFERS'] as $offer)
129 $offers[] = array_intersect_key(
131 array_flip([
'TREE',
'ID'])
135 $result[$productId][$offerId] = [
136 'SELECTED_VALUES' => $offerData[
'SELECTED_VALUES'] ??
null,
137 'EXISTING_VALUES_JSON' => Json::encode($offerData[
'EXISTING_VALUES'] ??
null),
138 'OFFERS_JSON' => Json::encode($offers),
139 'IBLOCK_ID' => $this->iblockInfo->getProductIblockId(),
152 $product[
'OFFERS_PROP'] =
false;
154 $skuPropCodes = array_keys($skuPropList);
155 $matrixFields = array_fill_keys($skuPropCodes,
false);
157 foreach ($product[
'OFFERS'] as $keyOffer => $offer)
159 if (isset($double[$offer[
'ID']]))
165 foreach ($skuPropCodes as $code)
170 $matrix[$keyOffer] = $row;
172 $double[$offer[
'ID']] =
true;
173 $newOffers[$keyOffer] = $offer;
176 $product[
'OFFERS'] = $newOffers;
179 $existingValues = [];
182 foreach ($skuPropCodes as $propCode)
184 $boolExist = $matrixFields[$propCode];
185 foreach ($matrix as $keyOffer => $row)
189 $offer =& $product[
'OFFERS'][$keyOffer];
190 $rowValue = $matrix[$keyOffer][$propCode][
'VALUE'];
191 $offer[
'TREE'][$skuPropList[$propCode][
'ID']] = $rowValue;
193 if ($selectedOfferId === $offer[
'ID'])
195 $product[
'SELECTED_VALUES'][$skuPropList[$propCode][
'ID']] = $rowValue;
198 $offer[
'SKU_SORT_'.$propCode] = $matrix[$keyOffer][$propCode][
'SORT'];
199 $sortFields[
'SKU_SORT_'.$propCode] = SORT_NUMERIC;
201 $usedFields[$propCode] = $skuPropList[$propCode];
202 $existingValues[$propCode][] = $rowValue;
206 unset($matrix[$keyOffer][$propCode]);
211 foreach ($existingValues as &$propertyValue)
213 $propertyValue = array_unique($propertyValue);
216 $product[
'OFFERS_PROP'] = $usedFields;
217 $product[
'EXISTING_VALUES'] = $existingValues;
219 Collection::sortByColumn($product[
'OFFERS'], $sortFields);
226 'SORT' => PHP_INT_MAX,
230 $skuPropSort = array_column($skuPropList[$code][
'VALUES'],
'SORT',
'ID');
232 if (isset($offer[
'DISPLAY_PROPERTIES'][$code]))
234 $matrixFields[$code] =
true;
237 if ($skuPropList[$code][
'USER_TYPE'] ===
'directory')
239 $intValue = $skuPropList[$code][
'XML_MAP'][$offer[
'DISPLAY_PROPERTIES'][$code][
'VALUE']] ?? 0;
240 $cell[
'VALUE'] = $intValue;
242 elseif ($skuPropList[$code][
'PROPERTY_TYPE'] ===
'L')
244 $cell[
'VALUE'] = (int)$offer[
'DISPLAY_PROPERTIES'][$code][
'VALUE_ENUM_ID'];
246 elseif ($skuPropList[$code][
'PROPERTY_TYPE'] ===
'E')
248 $cell[
'VALUE'] = (int)$offer[
'DISPLAY_PROPERTIES'][$code][
'VALUE'];
251 $cell[
'SORT'] = $skuPropSort[$cell[
'VALUE']];
307 $treeProperties = \CIBlockPriceTools::getTreeProperties(
308 $this->iblockInfo->toArray(),
309 $this->getPropertyCodes(),
310 $this->getDefaultValues()
314 \CIBlockPriceTools::getTreePropertyValues($treeProperties, $needValues);
316 foreach ($treeProperties as &$treeProperty)
318 if (!empty($treeProperty[
'VALUES']))
320 $treeProperty[
'VALUES'] = array_values($treeProperty[
'VALUES']);
324 return $treeProperties;