1515use Magento \Framework \Serialize \Serializer \Json ;
1616use Magento \Sales \Api \Data \InvoiceItemInterface ;
1717use Magento \Sales \Api \Data \OrderItemInterface ;
18- use Magento \SalesGraphQl \Model \Resolver \OrderItem \DataProvider as OrderItemProvider ;
1918
2019/**
2120 * Resolve bundle options items for order item
@@ -34,23 +33,15 @@ class BundleOptions implements ResolverInterface
3433 */
3534 private $ valueFactory ;
3635
37- /**
38- * @var OrderItemProvider
39- */
40- private $ orderItemProvider ;
41-
4236 /**
4337 * @param ValueFactory $valueFactory
44- * @param OrderItemProvider $orderItemProvider
4538 * @param Json $serializer
4639 */
4740 public function __construct (
4841 ValueFactory $ valueFactory ,
49- OrderItemProvider $ orderItemProvider ,
5042 Json $ serializer
5143 ) {
5244 $ this ->valueFactory = $ valueFactory ;
53- $ this ->orderItemProvider = $ orderItemProvider ;
5445 $ this ->serializer = $ serializer ;
5546 }
5647
@@ -66,13 +57,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6657 if ($ value ['model ' ] instanceof OrderItemInterface) {
6758 /** @var OrderItemInterface $item */
6859 $ item = $ value ['model ' ];
69- return $ this ->getBundleOptions ($ item );
60+ return $ this ->getBundleOptions ($ item, $ value );
7061 }
7162 if ($ value ['model ' ] instanceof InvoiceItemInterface) {
7263 /** @var InvoiceItemInterface $item */
7364 $ item = $ value ['model ' ];
7465 // Have to pass down order and item to map to avoid refetching all data
75- return $ this ->getBundleOptions ($ item ->getOrderItem ());
66+ return $ this ->getBundleOptions ($ item ->getOrderItem (), $ value );
7667 }
7768 return null ;
7869 });
@@ -82,10 +73,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8273 * Format bundle options and values from a parent bundle order item
8374 *
8475 * @param OrderItemInterface $item
76+ * @param array $formattedItem
8577 * @return array
8678 */
8779 private function getBundleOptions (
88- OrderItemInterface $ item
80+ OrderItemInterface $ item ,
81+ array $ formattedItem
8982 ): array {
9083 $ bundleOptions = [];
9184 if ($ item ->getProductType () === 'bundle ' ) {
@@ -98,6 +91,7 @@ private function getBundleOptions(
9891 if (isset ($ bundleOption ['option_id ' ])) {
9992 $ bundleOptions [$ bundleOptionId ]['values ' ] = $ this ->formatBundleOptionItems (
10093 $ item ,
94+ $ formattedItem ,
10195 $ bundleOption ['option_id ' ]
10296 );
10397 } else {
@@ -112,11 +106,13 @@ private function getBundleOptions(
112106 * Format Bundle items
113107 *
114108 * @param OrderItemInterface $item
109+ * @param array $formattedItem
115110 * @param string $bundleOptionId
116111 * @return array
117112 */
118113 private function formatBundleOptionItems (
119114 OrderItemInterface $ item ,
115+ array $ formattedItem ,
120116 string $ bundleOptionId
121117 ) {
122118 $ optionItems = [];
@@ -129,7 +125,6 @@ private function formatBundleOptionItems(
129125 // Value Id is missing from parent, so we have to match the child to parent option
130126 if (isset ($ bundleChildAttributes ['option_id ' ])
131127 && $ bundleChildAttributes ['option_id ' ] == $ bundleOptionId ) {
132- $ item = $ this ->orderItemProvider ->getOrderItemById ((int )$ childrenOrderItem ->getItemId ());
133128 $ optionItems [$ childrenOrderItem ->getItemId ()] = [
134129 'id ' => base64_encode ($ childrenOrderItem ->getItemId ()),
135130 'product_name ' => $ childrenOrderItem ->getName (),
@@ -139,7 +134,7 @@ private function formatBundleOptionItems(
139134 //use options price, not child price
140135 'value ' => $ bundleChildAttributes ['price ' ],
141136 //use currency from order
142- 'currency ' => $ item ['product_sale_price ' ]['currency ' ] ?? null ,
137+ 'currency ' => $ formattedItem ['product_sale_price ' ]['currency ' ] ?? null ,
143138 ]
144139 ];
145140 }
0 commit comments