Skip to content

Commit 647d8a5

Browse files
author
Prabhu Ram
committed
Merge remote-tracking branch 'origin/MC-20636' into MC-20637
2 parents d7b6bf8 + 885b06a commit 647d8a5

File tree

8 files changed

+241
-211
lines changed

8 files changed

+241
-211
lines changed

app/code/Magento/SalesGraphQl/Model/Resolver/OrderItem/DataProvider.php

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,50 @@ private function fetch()
129129
/** @var OrderInterface $associatedOrder */
130130
$associatedOrder = $orderList[$orderItem->getOrderId()];
131131
$itemOptions = $this->optionsProcessor->getItemOptions($orderItem);
132-
$this->orderItemList[$orderItem->getItemId()] = [
133-
'id' => base64_encode($orderItem->getItemId()),
134-
'product_name' => $orderItem->getName(),
135-
'product_sku' => $orderItem->getSku(),
136-
'product_url_key' => $associatedProduct ? $associatedProduct->getUrlKey() : null,
137-
'product_type' => $orderItem->getProductType(),
138-
'product_sale_price' => [
139-
'value' => $orderItem->getPrice(),
140-
'currency' => $associatedOrder->getOrderCurrencyCode()
141-
],
142-
'selected_options' => $itemOptions['selected_options'],
143-
'entered_options' => $itemOptions['entered_options'],
144-
'quantity_ordered' => $orderItem->getQtyOrdered(),
145-
'quantity_shipped' => $orderItem->getQtyShipped(),
146-
'quantity_refunded' => $orderItem->getQtyRefunded(),
147-
'quantity_invoiced' => $orderItem->getQtyInvoiced(),
148-
'quantity_canceled' => $orderItem->getQtyCanceled(),
149-
'quantity_returned' => $orderItem->getQtyReturned()
150-
];
132+
133+
if (!$orderItem->getParentItem()) {
134+
$this->orderItemList[$orderItem->getItemId()] = [
135+
'id' => base64_encode($orderItem->getItemId()),
136+
'product_name' => $orderItem->getName(),
137+
'product_sku' => $orderItem->getSku(),
138+
'product_url_key' => $associatedProduct ? $associatedProduct->getUrlKey() : null,
139+
'product_type' => $orderItem->getProductType(),
140+
'product_sale_price' => [
141+
'value' => $orderItem->getPrice(),
142+
'currency' => $associatedOrder->getOrderCurrencyCode()
143+
],
144+
'selected_options' => $itemOptions['selected_options'],
145+
'entered_options' => $itemOptions['entered_options'],
146+
'quantity_ordered' => $orderItem->getQtyOrdered(),
147+
'quantity_shipped' => $orderItem->getQtyShipped(),
148+
'quantity_refunded' => $orderItem->getQtyRefunded(),
149+
'quantity_invoiced' => $orderItem->getQtyInvoiced(),
150+
'quantity_canceled' => $orderItem->getQtyCanceled(),
151+
'quantity_returned' => $orderItem->getQtyReturned(),
152+
];
153+
} else {
154+
// case where
155+
$this->orderItemList[$orderItem->getParentItemId()]['child_items'][$orderItem->getItemId()] = [
156+
'id' => base64_encode($orderItem->getItemId()),
157+
'product_name' => $orderItem->getName(),
158+
'product_sku' => $orderItem->getSku(),
159+
'product_url_key' => $associatedProduct ? $associatedProduct->getUrlKey() : null,
160+
'product_type' => $orderItem->getProductType(),
161+
'product_sale_price' => [
162+
'value' => $orderItem->getPrice(),
163+
'currency' => $associatedOrder->getOrderCurrencyCode()
164+
],
165+
'selected_options' => $itemOptions['selected_options'],
166+
'entered_options' => $itemOptions['entered_options'],
167+
'quantity_ordered' => $orderItem->getQtyOrdered(),
168+
'quantity_shipped' => $orderItem->getQtyShipped(),
169+
'quantity_refunded' => $orderItem->getQtyRefunded(),
170+
'quantity_invoiced' => $orderItem->getQtyInvoiced(),
171+
'quantity_canceled' => $orderItem->getQtyCanceled(),
172+
'quantity_returned' => $orderItem->getQtyReturned(),
173+
];
174+
}
175+
151176
}
152177

153178
return $this->orderItemList;

app/code/Magento/SalesGraphQl/Model/Resolver/OrderItem/OptionsProcessor.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@
77

88
namespace Magento\SalesGraphQl\Model\Resolver\OrderItem;
99

10+
use Magento\Framework\Serialize\Serializer\Json;
1011
use Magento\Sales\Api\Data\OrderItemInterface;
1112

1213
/**
1314
* Process order item options to format for GraphQl output
1415
*/
1516
class OptionsProcessor
1617
{
18+
/**
19+
* Serializer
20+
*
21+
* @var Json
22+
*/
23+
private $serializer;
24+
25+
/**
26+
* @param Json $serializer
27+
*/
28+
public function __construct(Json $serializer)
29+
{
30+
$this->serializer = $serializer;
31+
}
32+
1733
/**
1834
* Get Order item options.
1935
*
@@ -82,4 +98,23 @@ private function processAttributesInfo(array $attributesInfo): array
8298
}
8399
return ['selected_options' => $selectedOptions, 'entered_options' => []];
84100
}
101+
102+
/**
103+
* TODO: use this method for bundle options
104+
*
105+
* @param mixed $item
106+
* @return mixed|null
107+
*/
108+
public function getSelectionAttributes($item)
109+
{
110+
if ($item instanceof \Magento\Sales\Model\Order\Item) {
111+
$options = $item->getProductOptions();
112+
} else {
113+
$options = $item->getOrderItem()->getProductOptions();
114+
}
115+
if (isset($options['bundle_selection_attributes'])) {
116+
return $this->serializer->unserialize($options['bundle_selection_attributes']);
117+
}
118+
return null;
119+
}
85120
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6060
$parentOrder = $value['model'];
6161
$orderItemIds = [];
6262
foreach ($parentOrder->getItems() as $item) {
63-
$orderItemIds[] = (int)$item->getItemId();
63+
if ((!$item->getParentItemId())) {
64+
$orderItemIds[] = (int)$item->getItemId();
65+
}
6466
$this->orderItemProvider->addOrderItemId((int)$item->getItemId());
6567
}
6668

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

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,29 @@ type CustomerOrder @doc(description: "Contains details about each of the custome
6161
}
6262

6363
interface OrderItemInterface @doc(description: "Order item details") @typeResolver(class: "Magento\\SalesGraphQl\\Model\\OrderItemTypeResolver") {
64-
id: ID! @doc(description: "Order item unique identifier")
65-
product_name: String @doc(description: "Name of the base product")
66-
product_sku: String! @doc(description: "SKU of the base product")
64+
id: ID! @doc(description: "The unique identifier of the order item")
65+
product_name: String @doc(description: "The name of the base product")
66+
product_sku: String! @doc(description: "The SKU of the base product")
6767
product_url_key: String @doc(description: "URL key of the base product")
68-
product_type: String @doc(description: "Type of product (e.g. simple, configurable, bundle)")
69-
status: String @doc(description: "The status of order item")
68+
product_type: String @doc(description: "The type of product, such as simple, configurable, or bundle")
69+
status: String @doc(description: "The status of the order item")
7070
product_sale_price: Money! @doc(description: "The sale price of the base product, including selected options")
71-
discounts: [Discount] @doc(description: "Final discount information for the product")
71+
discounts: [Discount] @doc(description: "The final discount information for the product")
7272
selected_options: [OrderItemOption] @doc(description: "The selected options for the base product, such as color or size")
7373
entered_options: [OrderItemOption] @doc(description: "The entered option for the base product, such as a logo or image")
7474
quantity_ordered: Float @doc(description: "The number of units ordered for this item")
7575
quantity_shipped: Float @doc(description: "The number of shipped items")
7676
quantity_refunded: Float @doc(description: "The number of refunded items")
7777
quantity_invoiced: Float @doc(description: "The number of invoiced items")
78-
quantity_canceled: Float @doc(description: "The number of cancelled items")
78+
quantity_canceled: Float @doc(description: "The number of canceled items")
7979
quantity_returned: Float @doc(description: "The number of returned items")
8080
}
8181

8282
type OrderItem implements OrderItemInterface {
8383
}
8484

8585
type BundleOrderItem implements OrderItemInterface {
86-
child_items: [OrderItemInterface]
86+
child_items: [OrderItemInterface] @doc(description: "A list of child products that are assigned to the bundle product")
8787
}
8888

8989
type OrderItemOption @doc(description: "Represents order item options like selected or entered") {
@@ -95,20 +95,20 @@ interface SalesTotalAmountInterface @doc(description: "Sales total details") @ty
9595
subtotal: Money! @doc(description: "The subtotal of the order, excluding shipping, discounts, and taxes")
9696
discounts: [Discount] @doc(description: "The applied discounts to the order")
9797
total_tax: Money! @doc(description: "The amount of tax applied to the order")
98-
taxes: [TaxItem] @doc(description: "The order taxes details")
98+
taxes: [TaxItem] @doc(description: "The order tax details")
9999
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes")
100100
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency")
101101
}
102102

103103
type TaxItem @doc(description: "The tax item details") {
104-
amount: Money! @doc(description: "The Tax amount")
105-
title: String! @doc(description: "The Tax item title")
106-
rate: Float @doc(description: "The Tax item rate")
104+
amount: Money! @doc(description: "The amount of tax applied to the item")
105+
title: String! @doc(description: "A title that describes the tax")
106+
rate: Float @doc(description: "The rate used to calculate the tax")
107107
}
108108
109109
type OrderTotal implements SalesTotalAmountInterface @doc(description: "Contains details about the sales total amounts used to calculate the final price") {
110-
total_shipping: Money! @doc(description: "The order shipping amount")
111-
shipping_handling: ShippingHandling @doc(description: "The shipping and handling costs details for the order")
110+
total_shipping: Money! @doc(description: "The shipping amount for the order")
111+
shipping_handling: ShippingHandling @doc(description: "Contains details about the shipping and handling costs for the order")
112112
}
113113

114114
type Invoice @doc(description: "Invoice details") {
@@ -120,66 +120,67 @@ type Invoice @doc(description: "Invoice details") {
120120
}
121121

122122
interface InvoiceItemInterface @doc(description: "Invoice item details") @typeResolver(class: "Magento\\SalesGraphQl\\Model\\InvoiceItemTypeResolver") {
123-
id: ID! @doc(description: "invoice item unique identifier")
124-
order_item: OrderItemInterface @doc(description: "associated order item")
125-
product_name: String @doc(description: "Name of the base product")
126-
product_sku: String! @doc(description: "SKU of the base product")
127-
product_type: String @doc(description: "Type of product (e.g. simple, configurable, bundle)")
128-
product_sale_price: Money! @doc(description: "Sale price for the base product including selected options")
129-
discounts: [Discount] @doc(description: "Final discount information for the base product including discounts on options")
130-
quantity_invoiced: Float @doc(description: "Number of invoiced items")
123+
id: ID! @doc(description: "The unique ID of the invoice item")
124+
order_item: OrderItemInterface @doc(description: "Contains details about an individual order item")
125+
product_name: String @doc(description: "The name of the base product")
126+
product_sku: String! @doc(description: "The SKU of the base product")
127+
product_type: String @doc(description: "The type of product, such as simple, configurable, or bundle")
128+
product_sale_price: Money! @doc(description: "The sale price for the base product including selected options")
129+
discounts: [Discount] @doc(description: "Contains information about the final discount amount for the base product, including discounts on options")
130+
quantity_invoiced: Float @doc(description: "The number of invoiced items")
131131
}
132132

133133
type InvoiceItem implements InvoiceItemInterface {
134134
}
135135

136136
type BundleInvoiceItem implements InvoiceItemInterface {
137-
child_items: [InvoiceItemInterface]
137+
child_items: [InvoiceItemInterface] @doc(description: "A list of child products that are assigned to the bundle product")
138138
}
139139

140140
type InvoiceTotal implements SalesTotalAmountInterface @doc(description: "Invoice total amount details") {
141-
total_shipping: Money! @doc(description: "order shipping amount")
142-
shipping_handling: ShippingHandling @doc(description: "shipping and handling for the order")
141+
total_shipping: Money! @doc(description: "The shipping amount for the invoice")
142+
shipping_handling: ShippingHandling @doc(description: "Contains details about the shipping and handling costs for the invoice")
143143
}
144144

145145
type ShippingHandling @doc(description: "The Shipping handling details") {
146-
total_amount: Money! @doc(description: "The Shipping total amount")
147-
amount_inc_tax: Money @doc(description: "The Shipping amount including tax")
148-
amount_exc_tax: Money @doc(description: "The Shipping amount excluding tax")
149-
taxes: [TaxItem] @doc(description: "The Shipping taxes details")
146+
total_amount: Money! @doc(description: "The total amount for shipping")
147+
amount_including_tax: Money @doc(description: "The shipping amount, including tax")
148+
amount_excluding_tax: Money @doc(description: "The shipping amount, excluding tax")
149+
taxes: [TaxItem] @doc(description: "Contains details about taxes applied for shipping")
150+
discounts: [Discount] @doc(description: "The applied discounts to the shipping")
150151
}
151152

152153
type OrderShipment @doc(description: "Order shipment details") {
153-
id: ID! @doc(description: "the ID of the shipment, used for API purposes")
154-
number: String! @doc(description: "sequential credit shipment number")
155-
tracking: [ShipmentTracking] @doc(description: "shipment tracking details")
156-
items: [ShipmentItem] @doc(description: "items included in the shipment")
157-
comments: [CommentItem] @doc(description: "comments on the shipment")
154+
id: ID! @doc(description: "The unique ID of the shipment")
155+
number: String! @doc(description: "The sequential credit shipment number")
156+
tracking: [ShipmentTracking] @doc(description: "Contains shipment tracking details")
157+
items: [ShipmentItem] @doc(description: "Contains items included in the shipment")
158+
comments: [CommentItem] @doc(description: "Comments added to the shipment")
158159
}
159160

160161
type CommentItem @doc(description: "Comment item details") {
161162
timestamp: String! @doc(description: "The timestamp of the comment")
162-
message: String! @doc(description: "the comment message")
163+
message: String! @doc(description: "The texat of the message")
163164
}
164165

165166
type ShipmentItem @doc(description: "Order shipment item details") {
166-
id: ID! @doc(description: "Shipment item unique identifier")
167-
order_item: OrderItemInterface @doc(description: "Associated order item")
168-
product_name: String @doc(description: "Name of the base product")
169-
product_sku: String! @doc(description: "SKU of the base product")
170-
product_sale_price: Money! @doc(description: "Sale price for the base product")
171-
quantity_shipped: Float! @doc(description: "Number of shipped items")
167+
id: ID! @doc(description: "The unique ID of the shipment item")
168+
order_item: OrderItemInterface @doc(description: "The shipped order item")
169+
product_name: String @doc(description: "The name of the base product")
170+
product_sku: String! @doc(description: "The SKU of the base product")
171+
product_sale_price: Money! @doc(description: "The sale price for the base product")
172+
quantity_shipped: Float! @doc(description: "The number of shipped items")
172173
}
173174

174175
type ShipmentTracking @doc(description: "Order shipment tracking details") {
175-
title: String! @doc(description: "Shipment tracking title")
176-
carrier: String! @doc(description: "Shipping carrier for the order delivery")
177-
number: String @doc(description: "Tracking number of the order shipment")
176+
title: String! @doc(description: "The shipment tracking title")
177+
carrier: String! @doc(description: "The shipping carrier for the order delivery")
178+
number: String @doc(description: "The tracking number of the order shipment")
178179
}
179180

180-
type PaymentMethod @doc(description: "Payment method used to pay for the order") {
181-
name: String! @doc(description: "Payment method name for e.g Paypal, etc.")
182-
type: String! @doc(description: "Payment method type used to pay for the order for e.g Credit Card, PayPal etc.")
181+
type PaymentMethod @doc(description: "Contains details about the payment method used to pay for the order") {
182+
name: String! @doc(description: "The label that describes the payment method")
183+
type: String! @doc(description: "The payment method code that indicates how the order was paid for")
183184
additional_data: [KeyValue] @doc(description: "Additional data per payment method type")
184185
}
185186

@@ -189,24 +190,24 @@ type KeyValue @doc(description: "The key-value type") {
189190
}
190191

191192
type CreditMemo @doc(description: "Credit memo details") {
192-
id: ID! @doc(description: "The ID of the credit memo, used for API purposes")
193-
number: String! @doc(description: "Sequential credit memo number")
194-
items: [CreditMemoItem] @doc(description: "An array with the items details refunded")
195-
total: CreditMemoTotal @doc(description: "Refund total amount details")
193+
id: ID! @doc(description: "The unique ID of the credit memo")
194+
number: String! @doc(description: "The sequential credit memo number")
195+
items: [CreditMemoItem] @doc(description: "An array containing details about refunded items")
196+
total: CreditMemoTotal @doc(description: "Contains details about the total refunded amount")
196197
comments: [CommentItem] @doc(description: "Comments on the credit memo")
197198
}
198199

199200
type CreditMemoItem @doc(description: "Credit memo item details") {
200-
id: ID! @doc(description: "Credit memo item unique identifier")
201-
order_item: OrderItemInterface @doc(description: "Associated order item")
202-
product_name: String @doc(description: "Name of the base product")
203-
product_sku: String! @doc(description: "SKU of the base product")
204-
product_sale_price: Money! @doc(description: "Sale price for the base product including selected options")
205-
discounts: [Discount] @doc(description: "Final discount information for the base product including discounts on options")
206-
quantity_invoiced: Float @doc(description: "Number of invoiced items")
201+
id: ID! @doc(description: "The unique ID of the credit memo item")
202+
order_item: OrderItemInterface @doc(description: "Contains details about a refunded order item")
203+
product_name: String @doc(description: "The name of the base product")
204+
product_sku: String! @doc(description: "The SKU of the base product")
205+
product_sale_price: Money! @doc(description: "The sale price for the base product, including selected options")
206+
discounts: [Discount] @doc(description: "The final discount information for the base product, including discounts on options")
207+
quantity_invoiced: Float @doc(description: "The number of invoiced items")
207208
}
208209

209-
type CreditMemoTotal implements SalesTotalAmountInterface @doc(description: "Credit memo price details") {
210+
type CreditMemoTotal implements SalesTotalAmountInterface @doc(description: "Contains credit memo price details") {
210211

211212
}
212213

0 commit comments

Comments
 (0)