Skip to content

Commit d91ac89

Browse files
committed
Merge branch 'MC-20636' of github.com:magento-honey-badgers/magento2ce into MC-20636
2 parents 601ec44 + 8b82c9d commit d91ac89

File tree

1 file changed

+51
-27
lines changed

1 file changed

+51
-27
lines changed

app/code/Magento/SalesGraphQl/Model/Resolver/BundleOptions.php

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8585
/**
8686
* Format bundle options and values from a parent bundle order item
8787
*
88-
* @param ExtensibleDataInterface $item
88+
* @param OrderItemInterface $item
89+
* @param Order|null $order
90+
* @param array|null $lineItemToOrderItemMap
8991
* @return array
9092
*/
9193
private function getBundleOptions(
@@ -96,35 +98,57 @@ private function getBundleOptions(
9698
$bundleOptions = [];
9799
if ($item->getProductType() === 'bundle') {
98100
$options = $item->getProductOptions();
99-
if (isset($options['bundle_options'])) {
100-
//loop through options
101-
foreach ($options['bundle_options'] as $bundleOptionKey => $bundleOption) {
102-
$bundleOptions[$bundleOptionKey]['label'] = $bundleOption['label'] ?? '';
103-
$bundleOptions[$bundleOptionKey]['id'] = isset($bundleOption['option_id']) ?
104-
base64_encode($bundleOption['option_id']) : null;
105-
$bundleOptions[$bundleOptionKey]['items'] = [];
106-
foreach ($bundleOption['value'] ?? [] as $bundleOptionValueKey => $bundleOptionValue) {
107-
// Find the item assign to the option
108-
/** @var OrderItemInterface $childrenOrderItem */
109-
foreach ($item->getChildrenItems() ?? [] as $childrenOrderItem) {
110-
$childOrderItemOptions = $childrenOrderItem->getProductOptions();
111-
$bundleChildAttributes = $this->serializer
112-
->unserialize($childOrderItemOptions['bundle_selection_attributes']);
113-
// Value Id is missing from parent, so we have to match the child to parent option
114-
if (isset($bundleChildAttributes['option_id'])
115-
&& $bundleChildAttributes['option_id'] == $bundleOption['option_id']) {
116-
$bundleOptions[$bundleOptionKey]['item_ids'][] = $childrenOrderItem->getItemId();
117-
if ($lineItemToOrderItemMap) {
118-
$bundleOptions[$bundleOptionKey]['items'][] =
119-
$lineItemToOrderItemMap[$childrenOrderItem->getItemId()];
120-
}
121-
}
122-
}
123-
$bundleOptions[$bundleOptionKey]['order'] = $order;
101+
//loop through options
102+
foreach ($options['bundle_options'] ?? [] as $bundleOptionId => $bundleOption) {
103+
$bundleOptions[$bundleOptionId]['label'] = $bundleOption['label'] ?? '';
104+
$bundleOptions[$bundleOptionId]['id'] = isset($bundleOption['option_id']) ?
105+
base64_encode($bundleOption['option_id']) : null;
106+
$optionItems = $this->formatBundleOptionItems(
107+
$item,
108+
$bundleOption,
109+
$lineItemToOrderItemMap
110+
);
111+
$bundleOptions[$bundleOptionId]['item_ids'] = $optionItems['item_ids'];
112+
$bundleOptions[$bundleOptionId]['items'] = $optionItems['items'] ?? [];
113+
$bundleOptions[$bundleOptionId]['order'] = $order;
114+
}
115+
}
116+
return $bundleOptions;
117+
}
118+
119+
/**
120+
* Format Bundle items
121+
*
122+
* @param OrderItemInterface $item
123+
* @param array $bundleOption
124+
* @param array|null $lineItemToOrderItemMap
125+
* @return array
126+
*/
127+
private function formatBundleOptionItems(
128+
OrderItemInterface $item,
129+
array $bundleOption,
130+
array $lineItemToOrderItemMap = null
131+
) {
132+
$optionItems = [];
133+
$optionItems['item_ids'] = [];
134+
$optionItems['items'] = [];
135+
foreach ($bundleOption['value'] ?? [] as $bundleOptionValueKey => $bundleOptionValue) {
136+
// Find the item assign to the option
137+
/** @var OrderItemInterface $childrenOrderItem */
138+
foreach ($item->getChildrenItems() ?? [] as $childrenOrderItem) {
139+
$childOrderItemOptions = $childrenOrderItem->getProductOptions();
140+
$bundleChildAttributes = $this->serializer
141+
->unserialize($childOrderItemOptions['bundle_selection_attributes']);
142+
// Value Id is missing from parent, so we have to match the child to parent option
143+
if (isset($bundleChildAttributes['option_id'])
144+
&& $bundleChildAttributes['option_id'] == $bundleOption['option_id']) {
145+
$optionItems['item_ids'][] = $childrenOrderItem->getItemId();
146+
if ($lineItemToOrderItemMap) {
147+
$optionItems['items'][] = $lineItemToOrderItemMap[$childrenOrderItem->getItemId()];
124148
}
125149
}
126150
}
127151
}
128-
return $bundleOptions;
152+
return $optionItems;
129153
}
130154
}

0 commit comments

Comments
 (0)