1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2025 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \SalesGraphQl \Model \Resolver ;
9
9
10
10
use Magento \Framework \Exception \LocalizedException ;
11
+ use Magento \Framework \Exception \NoSuchEntityException ;
11
12
use Magento \Framework \GraphQl \Config \Element \Field ;
12
13
use Magento \Framework \GraphQl \Query \ResolverInterface ;
13
14
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
14
15
use Magento \Sales \Api \Data \OrderInterface ;
16
+ use Magento \Tax \Api \OrderTaxManagementInterface ;
15
17
16
18
/**
17
19
* Resolve order totals taxes and discounts for order
18
20
*/
19
21
class OrderTotal implements ResolverInterface
20
22
{
23
+
24
+ /**
25
+ * OrderTotal Constructor
26
+ *
27
+ * @param OrderTaxManagementInterface $orderTaxManagement
28
+ */
29
+ public function __construct (
30
+ private readonly OrderTaxManagementInterface $ orderTaxManagement ,
31
+ ) {
32
+ }
33
+
21
34
/**
22
35
* @inheritDoc
23
36
*/
@@ -35,10 +48,12 @@ public function resolve(
35
48
/** @var OrderInterface $order */
36
49
$ order = $ value ['model ' ];
37
50
$ currency = $ order ->getOrderCurrencyCode ();
38
- $ baseCurrency = $ order ->getBaseCurrencyCode ();
39
51
40
52
return [
41
- 'base_grand_total ' => ['value ' => $ order ->getBaseGrandTotal (), 'currency ' => $ baseCurrency ],
53
+ 'base_grand_total ' => [
54
+ 'value ' => $ order ->getBaseGrandTotal (),
55
+ 'currency ' => $ order ->getBaseCurrencyCode ()
56
+ ],
42
57
'grand_total ' => ['value ' => $ order ->getGrandTotal (), 'currency ' => $ currency ],
43
58
'subtotal ' => ['value ' => $ order ->getSubtotal (), 'currency ' => $ currency ],
44
59
'total_tax ' => ['value ' => $ order ->getTaxAmount (), 'currency ' => $ currency ],
@@ -70,11 +85,12 @@ public function resolve(
70
85
*
71
86
* @param OrderInterface $order
72
87
* @return array
88
+ * @throws NoSuchEntityException
73
89
*/
74
90
private function getAllAppliedTaxesOnOrders (OrderInterface $ order ): array
75
91
{
76
- $ extensionAttributes = $ order ->getExtensionAttributes ( );
77
- $ appliedTaxes = $ extensionAttributes ->getAppliedTaxes () ?? [] ;
92
+ $ orderTaxDetails = $ this -> orderTaxManagement -> getOrderTaxDetails ( $ order ->getEntityId () );
93
+ $ appliedTaxes = $ orderTaxDetails ->getAppliedTaxes ();
78
94
$ allAppliedTaxOnOrders = [];
79
95
foreach ($ appliedTaxes as $ taxIndex => $ appliedTaxesData ) {
80
96
$ allAppliedTaxOnOrders [$ taxIndex ] = [
@@ -83,6 +99,7 @@ private function getAllAppliedTaxesOnOrders(OrderInterface $order): array
83
99
'amount ' => $ appliedTaxesData ->getDataByKey ('amount ' ),
84
100
];
85
101
}
102
+
86
103
return $ allAppliedTaxOnOrders ;
87
104
}
88
105
@@ -91,23 +108,21 @@ private function getAllAppliedTaxesOnOrders(OrderInterface $order): array
91
108
*
92
109
* @param OrderInterface $order
93
110
* @return array
111
+ * @throws NoSuchEntityException
94
112
*/
95
113
private function getAppliedTaxesDetails (OrderInterface $ order ): array
96
114
{
97
- $ allAppliedTaxOnOrders = $ this ->getAllAppliedTaxesOnOrders ($ order );
98
- $ taxes = [];
99
- foreach ($ allAppliedTaxOnOrders as $ appliedTaxes ) {
100
- $ appliedTaxesArray = [
115
+ return array_map (
116
+ fn ($ appliedTaxes ) => [
101
117
'rate ' => $ appliedTaxes ['percent ' ] ?? 0 ,
102
118
'title ' => $ appliedTaxes ['title ' ] ?? null ,
103
119
'amount ' => [
104
120
'value ' => $ appliedTaxes ['amount ' ] ?? 0 ,
105
- 'currency ' => $ order ->getOrderCurrencyCode ()
106
- ]
107
- ];
108
- $ taxes [] = $ appliedTaxesArray ;
109
- }
110
- return $ taxes ;
121
+ 'currency ' => $ order ->getOrderCurrencyCode (),
122
+ ],
123
+ ],
124
+ $ this ->getAllAppliedTaxesOnOrders ($ order )
125
+ );
111
126
}
112
127
113
128
/**
0 commit comments