9
9
10
10
use Magento \Framework \Api \SearchCriteriaBuilder ;
11
11
use Magento \Framework \Exception \InputException ;
12
- use Magento \Framework \Exception \LocalizedException ;
13
12
use Magento \Framework \GraphQl \Config \Element \Field ;
14
13
use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
15
14
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
18
17
use Magento \Sales \Api \Data \OrderInterface ;
19
18
use Magento \Sales \Api \OrderRepositoryInterface ;
20
19
use Magento \SalesGraphQl \Model \Resolver \CustomerOrders \Query \OrderFilter ;
20
+ use Magento \SalesGraphQl \Model \SalesItem \ExtractOrderAddressDetails ;
21
+ use Magento \SalesGraphQl \Model \SalesItem \ExtractOrderPaymentDetails ;
21
22
use Magento \Store \Api \Data \StoreInterface ;
22
23
23
24
/**
@@ -30,6 +31,16 @@ class CustomerOrders implements ResolverInterface
30
31
*/
31
32
private $ searchCriteriaBuilder ;
32
33
34
+ /**
35
+ * @var ExtractOrderAddressDetails
36
+ */
37
+ private $ extractOrderAddressDetails ;
38
+
39
+ /**
40
+ * @var ExtractOrderPaymentDetails
41
+ */
42
+ private $ extractOrderPaymentDetails ;
43
+
33
44
/**
34
45
* @var OrderRepositoryInterface
35
46
*/
@@ -42,15 +53,21 @@ class CustomerOrders implements ResolverInterface
42
53
43
54
/**
44
55
* @param OrderRepositoryInterface $orderRepository
56
+ * @param ExtractOrderAddressDetails $extractOrderAddressDetails
57
+ * @param ExtractOrderPaymentDetails $extractOrderPaymentDetails
45
58
* @param SearchCriteriaBuilder $searchCriteriaBuilder
46
59
* @param OrderFilter $orderFilter
47
60
*/
48
61
public function __construct (
49
62
OrderRepositoryInterface $ orderRepository ,
63
+ ExtractOrderAddressDetails $ extractOrderAddressDetails ,
64
+ ExtractOrderPaymentDetails $ extractOrderPaymentDetails ,
50
65
SearchCriteriaBuilder $ searchCriteriaBuilder ,
51
66
OrderFilter $ orderFilter
52
67
) {
53
68
$ this ->orderRepository = $ orderRepository ;
69
+ $ this ->extractOrderAddressDetails = $ extractOrderAddressDetails ;
70
+ $ this ->extractOrderPaymentDetails = $ extractOrderPaymentDetails ;
54
71
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
55
72
$ this ->orderFilter = $ orderFilter ;
56
73
}
@@ -77,19 +94,29 @@ public function resolve(
77
94
$ userId = $ context ->getUserId ();
78
95
/** @var StoreInterface $store */
79
96
$ store = $ context ->getExtensionAttributes ()->getStore ();
97
+ $ customerModel = $ value ['model ' ];
98
+ $ address = $ customerModel ->getAddresses ();
99
+ $ addressArrayData = [];
100
+ foreach ($ address as $ key => $ addressArray ) {
101
+ $ addressArrayData [$ key ] = $ addressArray ;
102
+ foreach ($ addressArray as $ addressData ) {
103
+ $ shipping = $ addressData ->isDefaultshipping ();
104
+ $ billing = $ addressData ->isDefaultBilling ();
105
+ }
106
+ }
80
107
81
108
try {
82
- $ searchResult = $ this ->getSearchResult ($ args , (int ) $ userId , (int )$ store ->getId ());
109
+ $ searchResult = $ this ->getSearchResult ($ args , (int )$ userId , (int )$ store ->getId ());
83
110
$ maxPages = (int )ceil ($ searchResult ->getTotalCount () / $ searchResult ->getPageSize ());
84
111
} catch (InputException $ e ) {
85
112
throw new GraphQlInputException (__ ($ e ->getMessage ()));
86
113
}
87
114
88
115
return [
89
116
'total_count ' => $ searchResult ->getTotalCount (),
90
- 'items ' => $ this ->formatOrdersArray ($ searchResult ->getItems ()),
91
- 'page_info ' => [
92
- 'page_size ' => $ searchResult ->getPageSize (),
117
+ 'items ' => $ this ->formatOrdersArray ($ searchResult ->getItems (), $ address ),
118
+ 'page_info ' => [
119
+ 'page_size ' => $ searchResult ->getPageSize (),
93
120
'current_page ' => $ searchResult ->getCurPage (),
94
121
'total_pages ' => $ maxPages ,
95
122
]
@@ -100,11 +127,13 @@ public function resolve(
100
127
* Format order models for graphql schema
101
128
*
102
129
* @param OrderInterface[] $orderModels
130
+ * @param array $address
103
131
* @return array
104
132
*/
105
- private function formatOrdersArray (array $ orderModels )
133
+ private function formatOrdersArray (array $ orderModels, array $ address )
106
134
{
107
135
$ ordersArray = [];
136
+
108
137
foreach ($ orderModels as $ orderModel ) {
109
138
$ ordersArray [] = [
110
139
'created_at ' => $ orderModel ->getCreatedAt (),
@@ -116,6 +145,9 @@ private function formatOrdersArray(array $orderModels)
116
145
'order_number ' => $ orderModel ->getIncrementId (),
117
146
'status ' => $ orderModel ->getStatusLabel (),
118
147
'shipping_method ' => $ orderModel ->getShippingDescription (),
148
+ 'billing_address ' => $ this ->extractOrderAddressDetails ->getBillingAddressDetails ($ orderModel ),
149
+ 'shipping_address ' => $ this ->extractOrderAddressDetails ->getShippingAddressDetails ($ orderModel ),
150
+ 'payment_methods ' => $ this ->extractOrderPaymentDetails ->getOrderPaymentMethodDetails ($ orderModel ),
119
151
'model ' => $ orderModel ,
120
152
];
121
153
}
@@ -144,3 +176,4 @@ private function getSearchResult(array $args, int $userId, int $storeId)
144
176
return $ this ->orderRepository ->getList ($ this ->searchCriteriaBuilder ->create ());
145
177
}
146
178
}
179
+
0 commit comments