11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2025 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \SalesGraphQl \Model \Resolver ;
99
1010use Magento \Framework \Exception \LocalizedException ;
11+ use Magento \Framework \Exception \NoSuchEntityException ;
1112use Magento \Framework \GraphQl \Config \Element \Field ;
1213use Magento \Framework \GraphQl \Query \ResolverInterface ;
1314use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
1415use Magento \Sales \Api \Data \OrderInterface ;
16+ use Magento \Tax \Api \OrderTaxManagementInterface ;
1517
1618/**
1719 * Resolve order totals taxes and discounts for order
1820 */
1921class OrderTotal implements ResolverInterface
2022{
23+
24+ /**
25+ * OrderTotal Constructor
26+ *
27+ * @param OrderTaxManagementInterface $orderTaxManagement
28+ */
29+ public function __construct (
30+ private readonly OrderTaxManagementInterface $ orderTaxManagement ,
31+ ) {
32+ }
33+
2134 /**
2235 * @inheritDoc
2336 */
@@ -35,10 +48,12 @@ public function resolve(
3548 /** @var OrderInterface $order */
3649 $ order = $ value ['model ' ];
3750 $ currency = $ order ->getOrderCurrencyCode ();
38- $ baseCurrency = $ order ->getBaseCurrencyCode ();
3951
4052 return [
41- 'base_grand_total ' => ['value ' => $ order ->getBaseGrandTotal (), 'currency ' => $ baseCurrency ],
53+ 'base_grand_total ' => [
54+ 'value ' => $ order ->getBaseGrandTotal (),
55+ 'currency ' => $ order ->getBaseCurrencyCode ()
56+ ],
4257 'grand_total ' => ['value ' => $ order ->getGrandTotal (), 'currency ' => $ currency ],
4358 'subtotal ' => ['value ' => $ order ->getSubtotal (), 'currency ' => $ currency ],
4459 'total_tax ' => ['value ' => $ order ->getTaxAmount (), 'currency ' => $ currency ],
@@ -70,11 +85,12 @@ public function resolve(
7085 *
7186 * @param OrderInterface $order
7287 * @return array
88+ * @throws NoSuchEntityException
7389 */
7490 private function getAllAppliedTaxesOnOrders (OrderInterface $ order ): array
7591 {
76- $ extensionAttributes = $ order ->getExtensionAttributes ( );
77- $ appliedTaxes = $ extensionAttributes ->getAppliedTaxes () ?? [] ;
92+ $ orderTaxDetails = $ this -> orderTaxManagement -> getOrderTaxDetails ( $ order ->getEntityId () );
93+ $ appliedTaxes = $ orderTaxDetails ->getAppliedTaxes ();
7894 $ allAppliedTaxOnOrders = [];
7995 foreach ($ appliedTaxes as $ taxIndex => $ appliedTaxesData ) {
8096 $ allAppliedTaxOnOrders [$ taxIndex ] = [
@@ -83,6 +99,7 @@ private function getAllAppliedTaxesOnOrders(OrderInterface $order): array
8399 'amount ' => $ appliedTaxesData ->getDataByKey ('amount ' ),
84100 ];
85101 }
102+
86103 return $ allAppliedTaxOnOrders ;
87104 }
88105
@@ -91,23 +108,21 @@ private function getAllAppliedTaxesOnOrders(OrderInterface $order): array
91108 *
92109 * @param OrderInterface $order
93110 * @return array
111+ * @throws NoSuchEntityException
94112 */
95113 private function getAppliedTaxesDetails (OrderInterface $ order ): array
96114 {
97- $ allAppliedTaxOnOrders = $ this ->getAllAppliedTaxesOnOrders ($ order );
98- $ taxes = [];
99- foreach ($ allAppliedTaxOnOrders as $ appliedTaxes ) {
100- $ appliedTaxesArray = [
115+ return array_map (
116+ fn ($ appliedTaxes ) => [
101117 'rate ' => $ appliedTaxes ['percent ' ] ?? 0 ,
102118 'title ' => $ appliedTaxes ['title ' ] ?? null ,
103119 'amount ' => [
104120 '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+ );
111126 }
112127
113128 /**
0 commit comments