1
1
<?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
2
6
3
7
namespace Magento \SalesGraphQl \Model \SalesItem ;
4
8
5
9
use Magento \Sales \Api \Data \OrderInterface ;
6
10
use Magento \Sales \Model \EntityInterface ;
7
11
use Magento \Tax \Api \Data \OrderTaxDetailsItemInterface ;
8
12
use Magento \Tax \Api \OrderTaxManagementInterface ;
13
+ use \Magento \Quote \Model \Quote \Address ;
9
14
10
15
class ShippingTaxCalculator
11
16
{
@@ -36,7 +41,7 @@ public function calculateShippingTaxes(
36
41
EntityInterface $ salesItem
37
42
) {
38
43
$ orderTaxDetails = $ this ->orderTaxManagement ->getOrderTaxDetails ($ order ->getId ());
39
- $ taxClassAmount = [];
44
+ $ taxClassBreakdown = [];
40
45
// Apply any taxes for shipping
41
46
$ shippingTaxAmount = $ salesItem ->getShippingTaxAmount ();
42
47
$ originalShippingTaxAmount = $ order ->getShippingTaxAmount ();
@@ -48,13 +53,12 @@ public function calculateShippingTaxes(
48
53
$ itemTaxDetails = $ orderTaxDetails ->getItems ();
49
54
foreach ($ itemTaxDetails as $ itemTaxDetail ) {
50
55
//Aggregate taxable items associated with shipping
51
- if ($ itemTaxDetail ->getType () == \ Magento \ Quote \ Model \ Quote \ Address::TYPE_SHIPPING ) {
52
- $ taxClassAmount = $ this ->_aggregateTaxes ( $ taxClassAmount , $ itemTaxDetail , $ shippingRatio );
56
+ if ($ itemTaxDetail ->getType () == Address::TYPE_SHIPPING ) {
57
+ $ taxClassBreakdown = $ this ->aggregateTaxes ( $ taxClassBreakdown , $ itemTaxDetail , $ shippingRatio );
53
58
}
54
59
}
55
60
}
56
-
57
- return $ taxClassAmount ;
61
+ return $ taxClassBreakdown ;
58
62
}
59
63
60
64
/**
@@ -70,31 +74,31 @@ public function calculateShippingTaxes(
70
74
* )
71
75
* )
72
76
*
73
- * @param array $taxClassAmount
77
+ * @param array $taxClassBreakdown
74
78
* @param OrderTaxDetailsItemInterface $itemTaxDetail
75
- * @param float $ratio
79
+ * @param float $taxRatio
76
80
* @return array
77
81
*/
78
- private function _aggregateTaxes ( $ taxClassAmount , OrderTaxDetailsItemInterface $ itemTaxDetail , $ ratio )
82
+ private function aggregateTaxes ( $ taxClassBreakdown , OrderTaxDetailsItemInterface $ itemTaxDetail , $ taxRatio )
79
83
{
80
84
$ itemAppliedTaxes = $ itemTaxDetail ->getAppliedTaxes ();
81
85
foreach ($ itemAppliedTaxes as $ itemAppliedTax ) {
82
- $ taxAmount = $ itemAppliedTax ->getAmount () * $ ratio ;
83
- $ baseTaxAmount = $ itemAppliedTax ->getBaseAmount () * $ ratio ;
86
+ $ taxAmount = $ itemAppliedTax ->getAmount () * $ taxRatio ;
87
+ $ baseTaxAmount = $ itemAppliedTax ->getBaseAmount () * $ taxRatio ;
84
88
if (0 == $ taxAmount && 0 == $ baseTaxAmount ) {
85
89
continue ;
86
90
}
87
91
$ taxCode = $ itemAppliedTax ->getCode ();
88
- if (!isset ($ taxClassAmount [$ taxCode ])) {
89
- $ taxClassAmount [$ taxCode ]['title ' ] = $ itemAppliedTax ->getTitle ();
90
- $ taxClassAmount [$ taxCode ]['percent ' ] = $ itemAppliedTax ->getPercent ();
91
- $ taxClassAmount [$ taxCode ]['tax_amount ' ] = $ taxAmount ;
92
- $ taxClassAmount [$ taxCode ]['base_tax_amount ' ] = $ baseTaxAmount ;
92
+ if (!isset ($ taxClassBreakdown [$ taxCode ])) {
93
+ $ taxClassBreakdown [$ taxCode ]['title ' ] = $ itemAppliedTax ->getTitle ();
94
+ $ taxClassBreakdown [$ taxCode ]['percent ' ] = $ itemAppliedTax ->getPercent ();
95
+ $ taxClassBreakdown [$ taxCode ]['tax_amount ' ] = $ taxAmount ;
96
+ $ taxClassBreakdown [$ taxCode ]['base_tax_amount ' ] = $ baseTaxAmount ;
93
97
} else {
94
- $ taxClassAmount [$ taxCode ]['tax_amount ' ] += $ taxAmount ;
95
- $ taxClassAmount [$ taxCode ]['base_tax_amount ' ] += $ baseTaxAmount ;
98
+ $ taxClassBreakdown [$ taxCode ]['tax_amount ' ] += $ taxAmount ;
99
+ $ taxClassBreakdown [$ taxCode ]['base_tax_amount ' ] += $ baseTaxAmount ;
96
100
}
97
101
}
98
- return $ taxClassAmount ;
102
+ return $ taxClassBreakdown ;
99
103
}
100
104
}
0 commit comments