Skip to content

Commit 0f3922c

Browse files
committed
Merge branch 'MC-20636' of github.com:magento-honey-badgers/magento2ce into MC-20636
# Conflicts: # app/code/Magento/SalesGraphQl/Model/Resolver/LineItem/DataProvider.php # dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/RetrieveOrdersByOrderNumberTest.php
2 parents 8282c5c + 9438a62 commit 0f3922c

File tree

9 files changed

+265
-440
lines changed

9 files changed

+265
-440
lines changed

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

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77

88
namespace Magento\SalesGraphQl\Model\Resolver;
99

10-
use Magento\Framework\Api\ExtensibleDataInterface;
1110
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\GraphQl\Config\Element\Field;
1312
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1413
use Magento\Framework\GraphQl\Query\ResolverInterface;
1514
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1615
use Magento\Framework\Serialize\Serializer\Json;
17-
use Magento\Sales\Api\Data\LineItemInterface;
16+
use Magento\Sales\Api\Data\InvoiceItemInterface;
1817
use Magento\Sales\Api\Data\OrderItemInterface;
19-
use Magento\Sales\Model\Order;
2018
use Magento\SalesGraphQl\Model\Resolver\OrderItem\DataProvider as OrderItemProvider;
2119

2220
/**
@@ -66,17 +64,15 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6664
throw new LocalizedException(__('"model" value should be specified'));
6765
}
6866
if ($value['model'] instanceof OrderItemInterface) {
69-
/** @var ExtensibleDataInterface $item */
67+
/** @var OrderItemInterface $item */
7068
$item = $value['model'];
71-
return $this->getBundleOptions($item, null, null);
69+
return $this->getBundleOptions($item);
7270
}
73-
if ($value['model'] instanceof LineItemInterface) {
74-
/** @var LineItemInterface $item */
71+
if ($value['model'] instanceof InvoiceItemInterface) {
72+
/** @var InvoiceItemInterface $item */
7573
$item = $value['model'];
76-
$lineItemToOrderItemMap = $value['line_item_to_order_item_map'];
77-
$order = $value['order'];
7874
// 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());
8076
}
8177
return null;
8278
});
@@ -86,14 +82,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8682
* Format bundle options and values from a parent bundle order item
8783
*
8884
* @param OrderItemInterface $item
89-
* @param Order|null $order
90-
* @param array|null $lineItemToOrderItemMap
9185
* @return array
9286
*/
9387
private function getBundleOptions(
94-
OrderItemInterface $item,
95-
Order $order = null,
96-
array $lineItemToOrderItemMap = null
88+
OrderItemInterface $item
9789
): array {
9890
$bundleOptions = [];
9991
if ($item->getProductType() === 'bundle') {
@@ -105,12 +97,9 @@ private function getBundleOptions(
10597
base64_encode($bundleOption['option_id']) : null;
10698
$optionItems = $this->formatBundleOptionItems(
10799
$item,
108-
$bundleOption,
109-
$lineItemToOrderItemMap
100+
$bundleOption
110101
);
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'] ?? [];
114103
}
115104
}
116105
return $bundleOptions;
@@ -121,16 +110,13 @@ private function getBundleOptions(
121110
*
122111
* @param OrderItemInterface $item
123112
* @param array $bundleOption
124-
* @param array|null $lineItemToOrderItemMap
125113
* @return array
126114
*/
127115
private function formatBundleOptionItems(
128116
OrderItemInterface $item,
129-
array $bundleOption,
130-
array $lineItemToOrderItemMap = null
117+
array $bundleOption
131118
) {
132119
$optionItems = [];
133-
$optionItems['item_ids'] = [];
134120
$optionItems['items'] = [];
135121
foreach ($bundleOption['value'] ?? [] as $bundleOptionValueKey => $bundleOptionValue) {
136122
// Find the item assign to the option
@@ -142,10 +128,15 @@ private function formatBundleOptionItems(
142128
// Value Id is missing from parent, so we have to match the child to parent option
143129
if (isset($bundleChildAttributes['option_id'])
144130
&& $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+
];
149140
}
150141
}
151142
}

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

Lines changed: 0 additions & 45 deletions
This file was deleted.

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

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Sales\Api\Data\InvoiceInterface as Invoice;
16+
use Magento\Sales\Api\Data\InvoiceItemInterface;
17+
use Magento\Sales\Api\Data\OrderItemInterface;
18+
use Magento\Sales\Model\Order;
19+
use Magento\SalesGraphQl\Model\Resolver\OrderItem\DataProvider as OrderItemProvider;
20+
21+
/**
22+
* Resolver for Invoice Items
23+
*/
24+
class InvoiceItems implements ResolverInterface
25+
{
26+
/**
27+
* @var ValueFactory
28+
*/
29+
private $valueFactory;
30+
31+
/**
32+
* @var OrderItemProvider
33+
*/
34+
private $orderItemProvider;
35+
36+
/**
37+
* @param ValueFactory $valueFactory
38+
* @param OrderItemProvider $orderItemProvider
39+
*/
40+
public function __construct(
41+
ValueFactory $valueFactory,
42+
OrderItemProvider $orderItemProvider
43+
) {
44+
$this->valueFactory = $valueFactory;
45+
$this->orderItemProvider = $orderItemProvider;
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function resolve(
52+
Field $field,
53+
$context,
54+
ResolveInfo $info,
55+
array $value = null,
56+
array $args = null
57+
) {
58+
if (!isset($value['model']) || !($value['model'] instanceof Invoice)) {
59+
throw new LocalizedException(__('"model" value should be specified'));
60+
}
61+
62+
if (!isset($value['order']) || !($value['order'] instanceof Order)) {
63+
throw new LocalizedException(__('"order" value should be specified'));
64+
}
65+
66+
/** @var Invoice $invoiceModel */
67+
$invoiceModel = $value['model'];
68+
$parentOrder = $value['order'];
69+
70+
return $this->valueFactory->create(
71+
$this->getInvoiceItems($parentOrder, $invoiceModel->getItems())
72+
);
73+
}
74+
75+
/**
76+
* Get Invoice Item Data
77+
*
78+
* @param Order $order
79+
* @param array $invoiceItems
80+
* @return \Closure
81+
*/
82+
public function getInvoiceItems(Order $order, array $invoiceItems)
83+
{
84+
$itemsList = [];
85+
foreach ($invoiceItems as $Item) {
86+
$this->orderItemProvider->addOrderItemId((int)$Item->getOrderItemId());
87+
}
88+
$itemsList = function () use ($order, $invoiceItems, $itemsList) {
89+
foreach ($invoiceItems as $invoiceItem) {
90+
$orderItem = $this->orderItemProvider->getOrderItemById((int)$invoiceItem->getOrderItemId());
91+
/** @var OrderItemInterface $orderItemModel */
92+
$orderItemModel = $orderItem['model'];
93+
if (!$orderItemModel->getParentItem()) {
94+
$invoiceItemData = $this->getInvoiceItemData($order, $invoiceItem);
95+
if (isset($invoiceItemData)) {
96+
$itemsList[$invoiceItem->getOrderItemId()] = $invoiceItemData;
97+
}
98+
}
99+
}
100+
return $itemsList;
101+
};
102+
return $itemsList;
103+
}
104+
105+
/**
106+
* Get resolved Invoice Item Data
107+
*
108+
* @param Order $order
109+
* @param InvoiceItemInterface $invoiceItem
110+
* @return array
111+
*/
112+
private function getInvoiceItemData(Order $order, InvoiceItemInterface $invoiceItem)
113+
{
114+
/** @var OrderItemInterface $orderItem */
115+
$orderItem = $this->orderItemProvider->getOrderItemById((int)$invoiceItem->getOrderItemId());
116+
return [
117+
'id' => base64_encode($invoiceItem->getEntityId()),
118+
'product_name' => $invoiceItem->getName(),
119+
'product_sku' => $invoiceItem->getSku(),
120+
'product_sale_price' => [
121+
'value' => $invoiceItem->getPrice(),
122+
'currency' => $order->getOrderCurrency()
123+
],
124+
'quantity_invoiced' => $invoiceItem->getQty(),
125+
'model' => $invoiceItem,
126+
'product_type' => $orderItem['product_type']
127+
];
128+
}
129+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function resolve(
3939
/** @var Invoice $invoice */
4040
foreach ($orderModel->getInvoiceCollection() as $invoice) {
4141
$invoices[] = [
42-
'id' => $invoice->getEntityId(),
42+
'id' => base64_encode($invoice->getEntityId()),
4343
'number' => $invoice['increment_id'],
4444
'model' => $invoice,
4545
'order' => $orderModel

0 commit comments

Comments
 (0)