@@ -85,7 +85,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
85
85
/**
86
86
* Format bundle options and values from a parent bundle order item
87
87
*
88
- * @param ExtensibleDataInterface $item
88
+ * @param OrderItemInterface $item
89
+ * @param Order|null $order
90
+ * @param array|null $lineItemToOrderItemMap
89
91
* @return array
90
92
*/
91
93
private function getBundleOptions (
@@ -96,35 +98,57 @@ private function getBundleOptions(
96
98
$ bundleOptions = [];
97
99
if ($ item ->getProductType () === 'bundle ' ) {
98
100
$ 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 ()];
124
148
}
125
149
}
126
150
}
127
151
}
128
- return $ bundleOptions ;
152
+ return $ optionItems ;
129
153
}
130
154
}
0 commit comments