Skip to content

Commit 6d92055

Browse files
merge magento/2.4-develop into magento-tsg/2.4-develop-pr66
2 parents fab0fa0 + 8f42112 commit 6d92055

File tree

5 files changed

+325
-56
lines changed

5 files changed

+325
-56
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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\Order;
9+
10+
use Magento\Sales\Api\Data\OrderAddressInterface;
11+
use Magento\Sales\Api\Data\OrderInterface;
12+
13+
/**
14+
* Class to get the order address details
15+
*/
16+
class OrderAddress
17+
{
18+
/**
19+
* Get the order Shipping address
20+
*
21+
* @param OrderInterface $order
22+
* @return array|null
23+
*/
24+
public function getOrderShippingAddress(
25+
OrderInterface $order
26+
): ?array {
27+
$shippingAddress = null;
28+
if ($order->getShippingAddress()) {
29+
$shippingAddress = $this->formatAddressData($order->getShippingAddress());
30+
}
31+
return $shippingAddress;
32+
}
33+
34+
/**
35+
* Get the order billing address
36+
*
37+
* @param OrderInterface $order
38+
* @return array|null
39+
*/
40+
public function getOrderBillingAddress(
41+
OrderInterface $order
42+
): ?array {
43+
$billingAddress = null;
44+
if ($order->getBillingAddress()) {
45+
$billingAddress = $this->formatAddressData($order->getBillingAddress());
46+
}
47+
return $billingAddress;
48+
}
49+
50+
/**
51+
* Customer Order address data formatter
52+
*
53+
* @param OrderAddressInterface $orderAddress
54+
* @return array
55+
*/
56+
private function formatAddressData(
57+
OrderAddressInterface $orderAddress
58+
): array {
59+
return
60+
[
61+
'firstname' => $orderAddress->getFirstname(),
62+
'lastname' => $orderAddress->getLastname(),
63+
'middlename' => $orderAddress->getMiddlename(),
64+
'postcode' => $orderAddress->getPostcode(),
65+
'prefix' => $orderAddress->getPrefix(),
66+
'suffix' => $orderAddress->getSuffix(),
67+
'street' => $orderAddress->getStreet(),
68+
'country_code' => $orderAddress->getCountryId(),
69+
'city' => $orderAddress->getCity(),
70+
'company' => $orderAddress->getCompany(),
71+
'fax' => $orderAddress->getFax(),
72+
'telephone' => $orderAddress->getTelephone(),
73+
'vat_id' => $orderAddress->getVatId(),
74+
'region_id' => $orderAddress->getRegionId(),
75+
'region' => $orderAddress->getRegion()
76+
];
77+
}
78+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Order;
9+
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
12+
/**
13+
* Class to get the order payment details
14+
*/
15+
class OrderPayments
16+
{
17+
/**
18+
* Get the order payment method
19+
*
20+
* @param OrderInterface $orderModel
21+
* @return array
22+
*/
23+
public function getOrderPaymentMethod(OrderInterface $orderModel): array
24+
{
25+
$orderPayment = $orderModel->getPayment();
26+
return [
27+
[
28+
'name' => $orderPayment->getAdditionalInformation()['method_title'] ?? '',
29+
'type' => $orderPayment->getMethod(),
30+
'additional_data' => []
31+
]
32+
];
33+
}
34+
}

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
use Magento\Framework\Api\SearchCriteriaBuilder;
1111
use Magento\Framework\Exception\InputException;
12-
use Magento\Framework\Exception\LocalizedException;
1312
use Magento\Framework\GraphQl\Config\Element\Field;
1413
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1514
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1615
use Magento\Framework\GraphQl\Query\ResolverInterface;
1716
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1817
use Magento\Sales\Api\Data\OrderInterface;
1918
use Magento\Sales\Api\OrderRepositoryInterface;
19+
use Magento\SalesGraphQl\Model\Order\OrderAddress;
20+
use Magento\SalesGraphQl\Model\Order\OrderPayments;
2021
use Magento\SalesGraphQl\Model\Resolver\CustomerOrders\Query\OrderFilter;
2122
use Magento\Store\Api\Data\StoreInterface;
2223

@@ -30,6 +31,16 @@ class CustomerOrders implements ResolverInterface
3031
*/
3132
private $searchCriteriaBuilder;
3233

34+
/**
35+
* @var OrderAddress
36+
*/
37+
private $orderAddress;
38+
39+
/**
40+
* @var OrderPayments
41+
*/
42+
private $orderPayments;
43+
3344
/**
3445
* @var OrderRepositoryInterface
3546
*/
@@ -42,15 +53,21 @@ class CustomerOrders implements ResolverInterface
4253

4354
/**
4455
* @param OrderRepositoryInterface $orderRepository
56+
* @param OrderAddress $orderAddress
57+
* @param OrderPayments $orderPayments
4558
* @param SearchCriteriaBuilder $searchCriteriaBuilder
4659
* @param OrderFilter $orderFilter
4760
*/
4861
public function __construct(
4962
OrderRepositoryInterface $orderRepository,
63+
OrderAddress $orderAddress,
64+
OrderPayments $orderPayments,
5065
SearchCriteriaBuilder $searchCriteriaBuilder,
5166
OrderFilter $orderFilter
5267
) {
5368
$this->orderRepository = $orderRepository;
69+
$this->orderAddress = $orderAddress;
70+
$this->orderPayments = $orderPayments;
5471
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
5572
$this->orderFilter = $orderFilter;
5673
}
@@ -77,9 +94,8 @@ public function resolve(
7794
$userId = $context->getUserId();
7895
/** @var StoreInterface $store */
7996
$store = $context->getExtensionAttributes()->getStore();
80-
8197
try {
82-
$searchResult = $this->getSearchResult($args, (int) $userId, (int)$store->getId());
98+
$searchResult = $this->getSearchResult($args, (int)$userId, (int)$store->getId());
8399
$maxPages = (int)ceil($searchResult->getTotalCount() / $searchResult->getPageSize());
84100
} catch (InputException $e) {
85101
throw new GraphQlInputException(__($e->getMessage()));
@@ -88,8 +104,8 @@ public function resolve(
88104
return [
89105
'total_count' => $searchResult->getTotalCount(),
90106
'items' => $this->formatOrdersArray($searchResult->getItems()),
91-
'page_info' => [
92-
'page_size' => $searchResult->getPageSize(),
107+
'page_info' => [
108+
'page_size' => $searchResult->getPageSize(),
93109
'current_page' => $searchResult->getCurPage(),
94110
'total_pages' => $maxPages,
95111
]
@@ -116,6 +132,9 @@ private function formatOrdersArray(array $orderModels)
116132
'order_number' => $orderModel->getIncrementId(),
117133
'status' => $orderModel->getStatusLabel(),
118134
'shipping_method' => $orderModel->getShippingDescription(),
135+
'shipping_address' => $this->orderAddress->getOrderShippingAddress($orderModel),
136+
'billing_address' => $this->orderAddress->getOrderBillingAddress($orderModel),
137+
'payment_methods' => $this->orderPayments->getOrderPaymentMethod($orderModel),
119138
'model' => $orderModel,
120139
];
121140
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ 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")
5050
payment_methods: [PaymentMethod] @doc(description: "Payment details for the order")
51-
shipping_address: CustomerAddress @doc(description: "The shipping address for the order")
52-
billing_address: CustomerAddress @doc(description: "The billing address for the order")
51+
shipping_address: OrderAddress @doc(description: "The shipping address for the order")
52+
billing_address: OrderAddress @doc(description: "The billing address for the order")
5353
carrier: String @doc(description: "The shipping carrier for the order delivery")
5454
shipping_method: String @doc(description: "The delivery method for the order")
5555
comments: [CommentItem] @doc(description: "Comments about the order")
@@ -59,6 +59,24 @@ type CustomerOrder @doc(description: "Contains details about each of the custome
5959
grand_total: Float @deprecated(reason: "Use the totals.grand_total attribute instead")
6060
}
6161

62+
type OrderAddress @doc(description: "OrderAddress contains detailed information about an order's billing and shipping addresses"){
63+
firstname: String! @doc(description: "The first name of the person associated with the shipping/billing address")
64+
lastname: String! @doc(description: "The family name of the person associated with the shipping/billing address")
65+
middlename: String @doc(description: "The middle name of the person associated with the shipping/billing address")
66+
region: String @doc(description: "The state or province name")
67+
region_id: ID @doc(description: "The unique ID for a pre-defined region")
68+
country_code: CountryCodeEnum @doc(description: "The customer's country")
69+
street: [String!]! @doc(description: "An array of strings that define the street number and name")
70+
company: String @doc(description: "The customer's company")
71+
telephone: String! @doc(description: "The telephone number")
72+
fax: String @doc(description: "The fax number")
73+
postcode: String @doc(description: "The customer's order ZIP or postal code")
74+
city: String! @doc(description: "The city or town")
75+
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
76+
suffix: String @doc(description: "A value such as Sr., Jr., or III")
77+
vat_id: String @doc(description: "The customer's Value-added tax (VAT) number (for corporate customers)")
78+
}
79+
6280
interface OrderItemInterface @doc(description: "Order item details") @typeResolver(class: "Magento\\SalesGraphQl\\Model\\OrderItemTypeResolver") {
6381
id: ID! @doc(description: "The unique identifier of the order item")
6482
product_name: String @doc(description: "The name of the base product")

0 commit comments

Comments
 (0)