@@ -95,11 +95,14 @@ private function getBundleOptions(
95
95
$ bundleOptions [$ bundleOptionId ]['label ' ] = $ bundleOption ['label ' ] ?? '' ;
96
96
$ bundleOptions [$ bundleOptionId ]['id ' ] = isset ($ bundleOption ['option_id ' ]) ?
97
97
base64_encode ($ bundleOption ['option_id ' ]) : null ;
98
- $ optionItems = $ this ->formatBundleOptionItems (
99
- $ item ,
100
- $ bundleOption
101
- );
102
- $ bundleOptions [$ bundleOptionId ]['values ' ] = $ optionItems ['items ' ] ?? [];
98
+ if (isset ($ bundleOption ['option_id ' ])) {
99
+ $ bundleOptions [$ bundleOptionId ]['values ' ] = $ this ->formatBundleOptionItems (
100
+ $ item ,
101
+ $ bundleOption ['option_id ' ]
102
+ );
103
+ } else {
104
+ $ bundleOptions [$ bundleOptionId ]['values ' ] = [];
105
+ }
103
106
}
104
107
}
105
108
return $ bundleOptions ;
@@ -109,37 +112,35 @@ private function getBundleOptions(
109
112
* Format Bundle items
110
113
*
111
114
* @param OrderItemInterface $item
112
- * @param array $bundleOption
115
+ * @param string $bundleOptionId
113
116
* @return array
114
117
*/
115
118
private function formatBundleOptionItems (
116
119
OrderItemInterface $ item ,
117
- array $ bundleOption
120
+ string $ bundleOptionId
118
121
) {
119
122
$ optionItems = [];
120
- $ optionItems ['items ' ] = [];
121
- foreach ($ bundleOption ['value ' ] ?? [] as $ bundleOptionValueKey => $ bundleOptionValue ) {
122
- // Find the item assign to the option
123
- /** @var OrderItemInterface $childrenOrderItem */
124
- foreach ($ item ->getChildrenItems () ?? [] as $ childrenOrderItem ) {
125
- $ childOrderItemOptions = $ childrenOrderItem ->getProductOptions ();
126
- $ bundleChildAttributes = $ this ->serializer
127
- ->unserialize ($ childOrderItemOptions ['bundle_selection_attributes ' ]);
128
- // Value Id is missing from parent, so we have to match the child to parent option
129
- if (isset ($ bundleChildAttributes ['option_id ' ])
130
- && $ bundleChildAttributes ['option_id ' ] == $ bundleOption ['option_id ' ]) {
131
- $ optionItems ['items ' ][$ childrenOrderItem ->getItemId ()] = [
132
- 'id ' => base64_encode ($ childrenOrderItem ->getItemId ()),
133
- 'product_name ' => $ childrenOrderItem ->getName (),
134
- 'product_sku ' => $ childrenOrderItem ->getSku (),
135
- 'quantity ' => $ bundleChildAttributes ['qty ' ],
136
- 'price ' => [
137
- 'value ' => $ bundleChildAttributes ['price ' ]
138
- ]
139
- ];
140
- }
123
+ // Find the item assign to the option
124
+ /** @var OrderItemInterface $childrenOrderItem */
125
+ foreach ($ item ->getChildrenItems () ?? [] as $ childrenOrderItem ) {
126
+ $ childOrderItemOptions = $ childrenOrderItem ->getProductOptions ();
127
+ $ bundleChildAttributes = $ this ->serializer
128
+ ->unserialize ($ childOrderItemOptions ['bundle_selection_attributes ' ] ?? '' );
129
+ // Value Id is missing from parent, so we have to match the child to parent option
130
+ if (isset ($ bundleChildAttributes ['option_id ' ])
131
+ && $ bundleChildAttributes ['option_id ' ] == $ bundleOptionId ) {
132
+ $ optionItems [$ childrenOrderItem ->getItemId ()] = [
133
+ 'id ' => base64_encode ($ childrenOrderItem ->getItemId ()),
134
+ 'product_name ' => $ childrenOrderItem ->getName (),
135
+ 'product_sku ' => $ childrenOrderItem ->getSku (),
136
+ 'quantity ' => $ bundleChildAttributes ['qty ' ],
137
+ 'price ' => [
138
+ 'value ' => $ bundleChildAttributes ['price ' ]
139
+ ]
140
+ ];
141
141
}
142
142
}
143
+
143
144
return $ optionItems ;
144
145
}
145
146
}
0 commit comments