11
11
use Magento \Framework \GraphQl \Config \Element \Field ;
12
12
use Magento \Framework \GraphQl \Query \ResolverInterface ;
13
13
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
14
+ use Magento \Sales \Api \Data \OrderExtensionInterface ;
14
15
use Magento \Sales \Api \Data \OrderInterface ;
15
16
16
17
class OrderTotal implements ResolverInterface
@@ -33,24 +34,9 @@ public function resolve(
33
34
$ order = $ value ['model ' ];
34
35
$ currency = $ order ->getOrderCurrencyCode ();
35
36
$ extensionAttributes = $ order ->getExtensionAttributes ();
36
- $ allAppliedTaxesForItemsData = [];
37
- $ appliedShippingTaxesForItemsData = [];
38
- foreach ($ extensionAttributes ->getItemAppliedTaxes () ?? [] as $ taxItemIndex => $ appliedTaxForItem ) {
39
- foreach ($ appliedTaxForItem ->getAppliedTaxes () ?? [] as $ taxLineItem ) {
40
- $ appliedShippingTaxesForItemsData [$ taxItemIndex ][$ taxItemIndex ] = [
41
- 'title ' => $ taxLineItem ->getDataByKey ('title ' ),
42
- 'percent ' => $ taxLineItem ->getDataByKey ('percent ' ),
43
- 'amount ' => $ taxLineItem ->getDataByKey ('amount ' ),
44
- ];
45
- if ($ appliedTaxForItem ->getType () === "shipping " ) {
46
- $ appliedShippingTaxesForItemsData [$ taxItemIndex ][$ taxItemIndex ] = [
47
- 'title ' => $ taxLineItem ->getDataByKey ('title ' ),
48
- 'percent ' => $ taxLineItem ->getDataByKey ('percent ' ),
49
- 'amount ' => $ taxLineItem ->getDataByKey ('amount ' )
50
- ];
51
- }
52
- }
53
- }
37
+
38
+ $ allAppliedTaxesForItemsData = $ this ->getAllAppliedTaxesForItemsData ($ extensionAttributes );
39
+ $ appliedShippingTaxesForItemsData = $ this ->getAppliedShippingTaxesForItemsData ($ extensionAttributes );
54
40
55
41
return [
56
42
'base_grand_total ' => ['value ' => $ order ->getBaseGrandTotal (), 'currency ' => $ currency ],
@@ -73,6 +59,46 @@ public function resolve(
73
59
];
74
60
}
75
61
62
+ /**
63
+ * @param OrderExtensionInterface $extensionAttributes
64
+ * @return array
65
+ */
66
+ private function getAllAppliedTaxesForItemsData (OrderExtensionInterface $ extensionAttributes ): array
67
+ {
68
+ $ allAppliedTaxesForItemsData = [];
69
+ foreach ($ extensionAttributes ->getItemAppliedTaxes () ?? [] as $ taxItemIndex => $ appliedTaxForItem ) {
70
+ foreach ($ appliedTaxForItem ->getAppliedTaxes () ?? [] as $ taxLineItem ) {
71
+ $ allAppliedTaxesForItemsData [$ taxItemIndex ][$ taxItemIndex ] = [
72
+ 'title ' => $ taxLineItem ->getDataByKey ('title ' ),
73
+ 'percent ' => $ taxLineItem ->getDataByKey ('percent ' ),
74
+ 'amount ' => $ taxLineItem ->getDataByKey ('amount ' ),
75
+ ];
76
+ }
77
+ }
78
+ return $ allAppliedTaxesForItemsData ;
79
+ }
80
+
81
+ /**
82
+ * @param OrderExtensionInterface $extensionAttributes
83
+ * @return array
84
+ */
85
+ private function getAppliedShippingTaxesForItemsData (OrderExtensionInterface $ extensionAttributes ): array
86
+ {
87
+ $ appliedShippingTaxesForItemsData = [];
88
+ foreach ($ extensionAttributes ->getItemAppliedTaxes () ?? [] as $ taxItemIndex => $ appliedTaxForItem ) {
89
+ foreach ($ appliedTaxForItem ->getAppliedTaxes () ?? [] as $ taxLineItem ) {
90
+ if ($ appliedTaxForItem ->getType () === "shipping " ) {
91
+ $ appliedShippingTaxesForItemsData [$ taxItemIndex ][$ taxItemIndex ] = [
92
+ 'title ' => $ taxLineItem ->getDataByKey ('title ' ),
93
+ 'percent ' => $ taxLineItem ->getDataByKey ('percent ' ),
94
+ 'amount ' => $ taxLineItem ->getDataByKey ('amount ' )
95
+ ];
96
+ }
97
+ }
98
+ }
99
+ return $ appliedShippingTaxesForItemsData ;
100
+ }
101
+
76
102
/**
77
103
* Return information about an applied discount
78
104
*
0 commit comments