Skip to content

Commit dde845c

Browse files
author
Prabhu Ram
committed
Merge remote-tracking branch 'origin/MC-20636-bundle' into MC-20637
2 parents 13fc3fb + 72a3afd commit dde845c

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

app/code/Magento/SalesGraphQl/Model/Resolver/BundleOptions.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Magento\GraphQl\Model\Query\ContextInterface;
1717
use Magento\SalesGraphQl\Model\Resolver\OrderItem\DataProvider as OrderItemProvider;
1818
use Magento\Sales\Api\Data\OrderItemInterface;
19+
use Magento\Sales\Api\Data\InvoiceItemInterface;
1920
use Magento\Framework\Serialize\Serializer\Json;
21+
use Magento\Framework\Api\ExtensibleDataInterface;
2022

2123
/**
2224
* Resolve bundle options items for order item
@@ -70,24 +72,34 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7072
if (!isset($value['model']) || !($value['model'] instanceof OrderItemInterface)) {
7173
throw new LocalizedException(__('"model" value should be specified'));
7274
}
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);
7678
});
7779
}
7880

7981

8082
/**
8183
* Format bundle options and values from a parent bundle order item
8284
*
83-
* @param OrderItemInterface $item
85+
* @param ExtensibleDataInterface $item
8486
* @return array
8587
*/
86-
private function getBundleOptions(OrderItemInterface $item): array
88+
private function getBundleOptions(ExtensibleDataInterface $item): array
8789
{
8890
$bundleOptions = [];
8991
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+
91103
if (isset($options['bundle_options'])) {
92104
//loop through options
93105
foreach ($options['bundle_options'] as $bundleOptionKey => $bundleOption) {

app/code/Magento/SalesGraphQl/etc/schema.graphqls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ type BundleOrderItem implements OrderItemInterface {
8787
}
8888

8989
type SelectedBundleOptionItems {
90-
label: String!
90+
id: ID! @doc(description: "The unique identifier of the option")
91+
label: String! @doc(description: "The label of the option")
9192
items: [OrderItem] @doc(description: "A list of products that represent the values of the parent option")
9293
}
9394

@@ -139,8 +140,7 @@ type InvoiceItem implements InvoiceItemInterface {
139140
}
140141

141142
type BundleInvoiceItem implements InvoiceItemInterface {
142-
bundle_options: [SelectedBundleOptionItems]
143-
child_items: [InvoiceItemInterface] @doc(description: "A list of child products that are assigned to the bundle product")
143+
bundle_options: [SelectedBundleOptionItems] @doc(description: "A list of bundle options that are assigned to the bundle product")
144144
}
145145

146146
type InvoiceTotal implements SalesTotalAmountInterface @doc(description: "Invoice total amount details") {

0 commit comments

Comments
 (0)