|
16 | 16 | use Magento\GraphQl\Model\Query\ContextInterface;
|
17 | 17 | use Magento\SalesGraphQl\Model\Resolver\OrderItem\DataProvider as OrderItemProvider;
|
18 | 18 | use Magento\Sales\Api\Data\OrderItemInterface;
|
| 19 | +use Magento\Sales\Api\Data\InvoiceItemInterface; |
19 | 20 | use Magento\Framework\Serialize\Serializer\Json;
|
| 21 | +use Magento\Framework\Api\ExtensibleDataInterface; |
20 | 22 |
|
21 | 23 | /**
|
22 | 24 | * Resolve bundle options items for order item
|
@@ -70,24 +72,34 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
|
70 | 72 | if (!isset($value['model']) || !($value['model'] instanceof OrderItemInterface)) {
|
71 | 73 | throw new LocalizedException(__('"model" value should be specified'));
|
72 | 74 | }
|
73 |
| - /** @var OrderItemInterface $orderItem */ |
74 |
| - $orderItem = $value['model']; |
75 |
| - return $this->getBundleOptions($orderItem); |
| 75 | + /** @var ExtensibleDataInterface $item */ |
| 76 | + $item = $value['model']; |
| 77 | + return $this->getBundleOptions($item); |
76 | 78 | });
|
77 | 79 | }
|
78 | 80 |
|
79 | 81 |
|
80 | 82 | /**
|
81 | 83 | * Format bundle options and values from a parent bundle order item
|
82 | 84 | *
|
83 |
| - * @param OrderItemInterface $item |
| 85 | + * @param ExtensibleDataInterface $item |
84 | 86 | * @return array
|
85 | 87 | */
|
86 |
| - private function getBundleOptions(OrderItemInterface $item): array |
| 88 | + private function getBundleOptions(ExtensibleDataInterface $item): array |
87 | 89 | {
|
88 | 90 | $bundleOptions = [];
|
89 | 91 | if ($item->getProductType() === 'bundle') {
|
90 |
| - $options = $item->getProductOptions(); |
| 92 | + $options = []; |
| 93 | + if ($item instanceof OrderItemInterface) { |
| 94 | + $options = $item->getProductOptions(); |
| 95 | + } elseif ($item instanceof InvoiceItemInterface) { |
| 96 | + $orderItemArray = $this->orderItemProvider |
| 97 | + ->getOrderItemById((int)$item->getOrderItemId()); |
| 98 | + /** @var OrderItemInterface $orderItem */ |
| 99 | + $orderItem = $orderItemArray['model']; |
| 100 | + $options = $orderItem->getProductOptions(); |
| 101 | + } |
| 102 | + |
91 | 103 | if (isset($options['bundle_options'])) {
|
92 | 104 | //loop through options
|
93 | 105 | foreach ($options['bundle_options'] as $bundleOptionKey => $bundleOption) {
|
|
0 commit comments