Skip to content

Commit 19c1f2c

Browse files
authored
Merge pull request #6002 from magento-honey-badgers/MC-36554
[honey] MC-32659: MyAccount :: Order Details :: Order Details by Order Number with additional different product types
2 parents d8a5df9 + 50c3d19 commit 19c1f2c

File tree

14 files changed

+1131
-14
lines changed

14 files changed

+1131
-14
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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\DownloadableGraphQl\Resolver\Order\Item;
9+
10+
use Magento\Downloadable\Model\ResourceModel\Link\Collection;
11+
use Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory;
12+
use Magento\DownloadableGraphQl\Model\ConvertLinksToArray;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\GraphQl\Config\Element\Field;
15+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
16+
use Magento\Framework\GraphQl\Query\ResolverInterface;
17+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
18+
use Magento\Framework\Serialize\Serializer\Json;
19+
use Magento\Sales\Api\Data\CreditmemoItemInterface;
20+
use Magento\Sales\Api\Data\InvoiceItemInterface;
21+
use Magento\Sales\Api\Data\OrderItemInterface;
22+
use Magento\Sales\Api\Data\ShipmentItemInterface;
23+
use Magento\Store\Api\Data\StoreInterface;
24+
25+
/**
26+
* Resolver fetches downloadable order item links and formats it according to the GraphQL schema.
27+
*/
28+
class Links implements ResolverInterface
29+
{
30+
/**
31+
* @var ConvertLinksToArray
32+
*/
33+
private $convertLinksToArray;
34+
35+
/**
36+
* @var CollectionFactory
37+
*/
38+
private $linkCollectionFactory;
39+
40+
/**
41+
* Serializer
42+
*
43+
* @var Json
44+
*/
45+
private $serializer;
46+
47+
/**
48+
* @var ValueFactory
49+
*/
50+
private $valueFactory;
51+
52+
/**
53+
* @param ConvertLinksToArray $convertLinksToArray
54+
* @param CollectionFactory $linkCollectionFactory
55+
* @param ValueFactory $valueFactory
56+
* @param Json $serializer
57+
*/
58+
public function __construct(
59+
ConvertLinksToArray $convertLinksToArray,
60+
CollectionFactory $linkCollectionFactory,
61+
ValueFactory $valueFactory,
62+
Json $serializer
63+
) {
64+
$this->convertLinksToArray = $convertLinksToArray;
65+
$this->linkCollectionFactory = $linkCollectionFactory;
66+
$this->valueFactory = $valueFactory;
67+
$this->serializer = $serializer;
68+
}
69+
70+
/**
71+
* @inheritdoc
72+
*/
73+
public function resolve(
74+
Field $field,
75+
$context,
76+
ResolveInfo $info,
77+
array $value = null,
78+
array $args = null
79+
) {
80+
/** @var StoreInterface $store */
81+
$store = $context->getExtensionAttributes()->getStore();
82+
83+
return $this->valueFactory->create(function () use ($value, $store) {
84+
if (!isset($value['model'])) {
85+
throw new LocalizedException(__('"model" value should be specified'));
86+
}
87+
88+
if ($value['model'] instanceof OrderItemInterface) {
89+
return $this->formatLinksData($value['model'], $store);
90+
} elseif ($value['model'] instanceof InvoiceItemInterface
91+
|| $value['model'] instanceof CreditmemoItemInterface
92+
|| $value['model'] instanceof ShipmentItemInterface) {
93+
$item = $value['model'];
94+
return $this->formatLinksData($item->getOrderItem(), $store);
95+
}
96+
return null;
97+
});
98+
}
99+
100+
/**
101+
* Format values from order links item
102+
*
103+
* @param OrderItemInterface $item
104+
* @param StoreInterface $store
105+
* @return array
106+
*/
107+
private function formatLinksData(
108+
OrderItemInterface $item,
109+
StoreInterface $store
110+
): array {
111+
$linksData = [];
112+
if ($item->getProductType() === 'downloadable') {
113+
$orderLinks = $item->getProductOptionByCode('links') ?? [];
114+
115+
/** @var Collection */
116+
$linksCollection = $this->linkCollectionFactory->create();
117+
$linksCollection->addTitleToResult($store->getId())
118+
->addPriceToResult($store->getWebsiteId())
119+
->addFieldToFilter('main_table.link_id', ['in' => $orderLinks]);
120+
121+
$linksData = $this->convertLinksToArray->execute($linksCollection->getItems());
122+
}
123+
return $linksData;
124+
}
125+
}

app/code/Magento/DownloadableGraphQl/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
"type": "magento2-module",
55
"require": {
66
"php": "~7.3.0||~7.4.0",
7+
"magento/module-store": "*",
78
"magento/module-catalog": "*",
89
"magento/module-downloadable": "*",
910
"magento/module-quote": "*",
11+
"magento/module-sales": "*",
1012
"magento/module-quote-graph-ql": "*",
1113
"magento/framework": "*"
1214
},
1315
"suggest": {
14-
"magento/module-catalog-graph-ql": "*"
16+
"magento/module-catalog-graph-ql": "*",
17+
"magento/module-sales-graph-ql": "*"
1518
},
1619
"license": [
1720
"OSL-3.0",

app/code/Magento/DownloadableGraphQl/etc/graphql/di.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,25 @@
3939
</argument>
4040
</arguments>
4141
</type>
42+
<type name="Magento\SalesGraphQl\Model\TypeResolver\OrderItem">
43+
<arguments>
44+
<argument name="productTypeMap" xsi:type="array">
45+
<item name="downloadable" xsi:type="string">DownloadableOrderItem</item>
46+
</argument>
47+
</arguments>
48+
</type>
49+
<type name="Magento\SalesGraphQl\Model\TypeResolver\InvoiceItem">
50+
<arguments>
51+
<argument name="productTypeMap" xsi:type="array">
52+
<item name="downloadable" xsi:type="string">DownloadableInvoiceItem</item>
53+
</argument>
54+
</arguments>
55+
</type>
56+
<type name="Magento\SalesGraphQl\Model\TypeResolver\CreditMemoItem">
57+
<arguments>
58+
<argument name="productTypeMap" xsi:type="array">
59+
<item name="downloadable" xsi:type="string">DownloadableCreditMemoItem</item>
60+
</argument>
61+
</arguments>
62+
</type>
4263
</config>

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type DownloadableProductLinks @doc(description: "DownloadableProductLinks define
5353
link_type: DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample")
5454
sample_type: DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample")
5555
sample_file: String @deprecated(reason: "`sample_url` serves to get the downloadable sample")
56-
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Product\\DownloadableLinksValueUid") # A Base64 string that encodes option details.
56+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Product\\DownloadableLinksValueUid")
5757
}
5858

5959
type DownloadableProductSamples @doc(description: "DownloadableProductSamples defines characteristics of a downloadable product") {
@@ -64,3 +64,21 @@ type DownloadableProductSamples @doc(description: "DownloadableProductSamples de
6464
sample_type: DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample")
6565
sample_file: String @deprecated(reason: "`sample_url` serves to get the downloadable sample")
6666
}
67+
68+
type DownloadableOrderItem implements OrderItemInterface {
69+
downloadable_links: [DownloadableItemsLinks] @doc(description: "A list of downloadable links that are ordered from the downloadable product") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Order\\Item\\Links")
70+
}
71+
72+
type DownloadableInvoiceItem implements InvoiceItemInterface {
73+
downloadable_links: [DownloadableItemsLinks] @doc(description: "A list of downloadable links that are invoiced from the downloadable product") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Order\\Item\\Links")
74+
}
75+
76+
type DownloadableCreditMemoItem implements CreditMemoItemInterface {
77+
downloadable_links: [DownloadableItemsLinks] @doc(description: "A list of downloadable links that are refunded from the downloadable product") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Order\\Item\\Links")
78+
}
79+
80+
type DownloadableItemsLinks @doc(description: "DownloadableProductLinks defines characteristics of a downloadable product") {
81+
title: String @doc(description: "The display name of the link")
82+
sort_order: Int @doc(description: "A number indicating the sort order")
83+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\Product\\DownloadableLinksValueUid")
84+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ private function processOptions(array $options): array
4949
if (isset($option['option_type'])) {
5050
if (in_array($option['option_type'], ['field', 'area', 'file', 'date', 'date_time', 'time'])) {
5151
$selectedOptions[] = [
52-
'id' => $option['label'],
52+
'label' => $option['label'],
5353
'value' => $option['print_value'] ?? $option['value'],
5454
];
5555
} elseif (in_array($option['option_type'], ['drop_down', 'radio', 'checkbox', 'multiple'])) {
5656
$enteredOptions[] = [
57-
'id' => $option['label'],
57+
'label' => $option['label'],
5858
'value' => $option['print_value'] ?? $option['value'],
5959
];
6060
}
@@ -74,7 +74,7 @@ private function processAttributesInfo(array $attributesInfo): array
7474
$selectedOptions = [];
7575
foreach ($attributesInfo ?? [] as $option) {
7676
$selectedOptions[] = [
77-
'id' => $option['label'],
77+
'label' => $option['label'],
7878
'value' => $option['print_value'] ?? $option['value'],
7979
];
8080
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ type CustomerOrder @doc(description: "Contains details about each of the custome
4848
invoices: [Invoice]! @doc(description: "A list of invoices for the order") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Invoices")
4949
shipments: [OrderShipment] @doc(description: "A list of shipments for the order") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Shipments")
5050
credit_memos: [CreditMemo] @doc(description: "A list of credit memos") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\CreditMemos")
51-
payment_methods: [PaymentMethod] @doc(description: "Payment details for the order")
51+
payment_methods: [OrderPaymentMethod] @doc(description: "Payment details for the order")
5252
shipping_address: OrderAddress @doc(description: "The shipping address for the order")
5353
billing_address: OrderAddress @doc(description: "The billing address for the order")
5454
carrier: String @doc(description: "The shipping carrier for the order delivery") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\CustomerOrders\\Carrier")
5555
shipping_method: String @doc(description: "The delivery method for the order")
56-
comments: [CommentItem] @doc(description: "Comments about the order")
56+
comments: [SalesCommentItem] @doc(description: "Comments about the order")
5757
increment_id: String @deprecated(reason: "Use the id attribute instead")
5858
order_number: String! @deprecated(reason: "Use the number attribute instead")
5959
created_at: String @deprecated(reason: "Use the order_date attribute instead")
@@ -101,7 +101,7 @@ type OrderItem implements OrderItemInterface {
101101
}
102102

103103
type OrderItemOption @doc(description: "Represents order item options like selected or entered") {
104-
id: String! @doc(description: "The name of the option")
104+
label: String! @doc(description: "The name of the option")
105105
value: String! @doc(description: "The value of the option")
106106
}
107107

@@ -127,7 +127,7 @@ type Invoice @doc(description: "Invoice details") {
127127
number: String! @doc(description: "Sequential invoice number")
128128
total: InvoiceTotal @doc(description: "Invoice total amount details") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Invoice\\InvoiceTotal")
129129
items: [InvoiceItemInterface] @doc(description: "Invoiced product details") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Invoice\\InvoiceItems")
130-
comments: [CommentItem] @doc(description: "Comments on the invoice")
130+
comments: [SalesCommentItem] @doc(description: "Comments on the invoice")
131131
}
132132

133133
interface InvoiceItemInterface @doc(description: "Invoice item details") @typeResolver(class: "Magento\\SalesGraphQl\\Model\\TypeResolver\\InvoiceItem") {
@@ -171,10 +171,10 @@ type OrderShipment @doc(description: "Order shipment details") {
171171
number: String! @doc(description: "The sequential credit shipment number")
172172
tracking: [ShipmentTracking] @doc(description: "Contains shipment tracking details") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Shipment\\ShipmentTracking")
173173
items: [ShipmentItemInterface] @doc(description: "Contains items included in the shipment") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Shipment\\ShipmentItems")
174-
comments: [CommentItem] @doc(description: "Comments added to the shipment")
174+
comments: [SalesCommentItem] @doc(description: "Comments added to the shipment")
175175
}
176176

177-
type CommentItem @doc(description: "Comment item details") {
177+
type SalesCommentItem @doc(description: "Comment item details") {
178178
timestamp: String! @doc(description: "The timestamp of the comment")
179179
message: String! @doc(description: "The text of the message")
180180
}
@@ -197,7 +197,7 @@ type ShipmentTracking @doc(description: "Order shipment tracking details") {
197197
number: String @doc(description: "The tracking number of the order shipment")
198198
}
199199

200-
type PaymentMethod @doc(description: "Contains details about the payment method used to pay for the order") {
200+
type OrderPaymentMethod @doc(description: "Contains details about the payment method used to pay for the order") {
201201
name: String! @doc(description: "The label that describes the payment method")
202202
type: String! @doc(description: "The payment method code that indicates how the order was paid for")
203203
additional_data: [KeyValue] @doc(description: "Additional data per payment method type")
@@ -208,7 +208,7 @@ type CreditMemo @doc(description: "Credit memo details") {
208208
number: String! @doc(description: "The sequential credit memo number")
209209
items: [CreditMemoItemInterface] @doc(description: "An array containing details about refunded items") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\CreditMemo\\CreditMemoItems")
210210
total: CreditMemoTotal @doc(description: "Contains details about the total refunded amount") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\CreditMemo\\CreditMemoTotal")
211-
comments: [CommentItem] @doc(description: "Comments on the credit memo") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\CreditMemo\\CreditMemoComments")
211+
comments: [SalesCommentItem] @doc(description: "Comments on the credit memo") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\CreditMemo\\CreditMemoComments")
212212
}
213213

214214
interface CreditMemoItemInterface @doc(description: "Credit memo item details") @typeResolver(class: "Magento\\SalesGraphQl\\Model\\TypeResolver\\CreditMemoItem") {

0 commit comments

Comments
 (0)