7
7
8
8
namespace Magento \SalesGraphQl \Model \Resolver ;
9
9
10
- use Magento \Framework \Api \ExtensibleDataInterface ;
11
10
use Magento \Framework \Exception \LocalizedException ;
12
11
use Magento \Framework \GraphQl \Config \Element \Field ;
13
12
use Magento \Framework \GraphQl \Query \Resolver \ValueFactory ;
14
13
use Magento \Framework \GraphQl \Query \ResolverInterface ;
15
14
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
16
15
use Magento \Framework \Serialize \Serializer \Json ;
17
- use Magento \Sales \Api \Data \LineItemInterface ;
16
+ use Magento \Sales \Api \Data \InvoiceItemInterface ;
18
17
use Magento \Sales \Api \Data \OrderItemInterface ;
19
- use Magento \Sales \Model \Order ;
20
18
use Magento \SalesGraphQl \Model \Resolver \OrderItem \DataProvider as OrderItemProvider ;
21
19
22
20
/**
@@ -66,17 +64,15 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
66
64
throw new LocalizedException (__ ('"model" value should be specified ' ));
67
65
}
68
66
if ($ value ['model ' ] instanceof OrderItemInterface) {
69
- /** @var ExtensibleDataInterface $item */
67
+ /** @var OrderItemInterface $item */
70
68
$ item = $ value ['model ' ];
71
- return $ this ->getBundleOptions ($ item, null , null );
69
+ return $ this ->getBundleOptions ($ item );
72
70
}
73
- if ($ value ['model ' ] instanceof LineItemInterface ) {
74
- /** @var LineItemInterface $item */
71
+ if ($ value ['model ' ] instanceof InvoiceItemInterface ) {
72
+ /** @var InvoiceItemInterface $item */
75
73
$ item = $ value ['model ' ];
76
- $ lineItemToOrderItemMap = $ value ['line_item_to_order_item_map ' ];
77
- $ order = $ value ['order ' ];
78
74
// Have to pass down order and item to map to avoid refetching all data
79
- return $ this ->getBundleOptions ($ item ->getOrderItem (), $ order , $ lineItemToOrderItemMap );
75
+ return $ this ->getBundleOptions ($ item ->getOrderItem ());
80
76
}
81
77
return null ;
82
78
});
@@ -86,14 +82,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
86
82
* Format bundle options and values from a parent bundle order item
87
83
*
88
84
* @param OrderItemInterface $item
89
- * @param Order|null $order
90
- * @param array|null $lineItemToOrderItemMap
91
85
* @return array
92
86
*/
93
87
private function getBundleOptions (
94
- OrderItemInterface $ item ,
95
- Order $ order = null ,
96
- array $ lineItemToOrderItemMap = null
88
+ OrderItemInterface $ item
97
89
): array {
98
90
$ bundleOptions = [];
99
91
if ($ item ->getProductType () === 'bundle ' ) {
@@ -105,12 +97,9 @@ private function getBundleOptions(
105
97
base64_encode ($ bundleOption ['option_id ' ]) : null ;
106
98
$ optionItems = $ this ->formatBundleOptionItems (
107
99
$ item ,
108
- $ bundleOption ,
109
- $ lineItemToOrderItemMap
100
+ $ bundleOption
110
101
);
111
- $ bundleOptions [$ bundleOptionId ]['item_ids ' ] = $ optionItems ['item_ids ' ];
112
- $ bundleOptions [$ bundleOptionId ]['items ' ] = $ optionItems ['items ' ] ?? [];
113
- $ bundleOptions [$ bundleOptionId ]['order ' ] = $ order ;
102
+ $ bundleOptions [$ bundleOptionId ]['values ' ] = $ optionItems ['items ' ] ?? [];
114
103
}
115
104
}
116
105
return $ bundleOptions ;
@@ -121,16 +110,13 @@ private function getBundleOptions(
121
110
*
122
111
* @param OrderItemInterface $item
123
112
* @param array $bundleOption
124
- * @param array|null $lineItemToOrderItemMap
125
113
* @return array
126
114
*/
127
115
private function formatBundleOptionItems (
128
116
OrderItemInterface $ item ,
129
- array $ bundleOption ,
130
- array $ lineItemToOrderItemMap = null
117
+ array $ bundleOption
131
118
) {
132
119
$ optionItems = [];
133
- $ optionItems ['item_ids ' ] = [];
134
120
$ optionItems ['items ' ] = [];
135
121
foreach ($ bundleOption ['value ' ] ?? [] as $ bundleOptionValueKey => $ bundleOptionValue ) {
136
122
// Find the item assign to the option
@@ -142,10 +128,15 @@ private function formatBundleOptionItems(
142
128
// Value Id is missing from parent, so we have to match the child to parent option
143
129
if (isset ($ bundleChildAttributes ['option_id ' ])
144
130
&& $ bundleChildAttributes ['option_id ' ] == $ bundleOption ['option_id ' ]) {
145
- $ optionItems ['item_ids ' ][] = $ childrenOrderItem ->getItemId ();
146
- if ($ lineItemToOrderItemMap ) {
147
- $ optionItems ['items ' ][] = $ lineItemToOrderItemMap [$ childrenOrderItem ->getItemId ()];
148
- }
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
+ ];
149
140
}
150
141
}
151
142
}
0 commit comments