3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \SalesGraphQl \Model \SalesItem ;
8
9
9
10
use Magento \Sales \Api \Data \OrderInterface ;
10
11
use Magento \Sales \Model \EntityInterface ;
11
12
use Magento \Tax \Api \Data \OrderTaxDetailsItemInterface ;
12
13
use Magento \Tax \Api \OrderTaxManagementInterface ;
13
- use \Magento \Quote \Model \Quote \Address ;
14
+ use Magento \Quote \Model \Quote \Address ;
15
+ use Magento \Framework \Exception \NoSuchEntityException ;
14
16
17
+ /**
18
+ * Calculates shipping taxes for sales items (Invoices, Credit memo)
19
+ */
15
20
class ShippingTaxCalculator
16
21
{
17
22
/**
@@ -34,12 +39,12 @@ public function __construct(
34
39
* @param OrderInterface $order
35
40
* @param EntityInterface $salesItem
36
41
* @return array
37
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
42
+ * @throws NoSuchEntityException
38
43
*/
39
44
public function calculateShippingTaxes (
40
45
OrderInterface $ order ,
41
46
EntityInterface $ salesItem
42
- ) {
47
+ ): array {
43
48
$ orderTaxDetails = $ this ->orderTaxManagement ->getOrderTaxDetails ($ order ->getId ());
44
49
$ taxClassBreakdown = [];
45
50
// Apply any taxes for shipping
@@ -64,7 +69,7 @@ public function calculateShippingTaxes(
64
69
/**
65
70
* Accumulates the pre-calculated taxes for each tax class
66
71
*
67
- * This method accepts and returns the 'taxClassAmount ' array with format:
72
+ * This method accepts and returns the '$taxClassBreakdown ' array with format:
68
73
* array(
69
74
* $index => array(
70
75
* 'tax_amount' => $taxAmount,
@@ -74,13 +79,16 @@ public function calculateShippingTaxes(
74
79
* )
75
80
* )
76
81
*
77
- * @param array $taxClassBreakdown
82
+ * @param array $taxClassBreakdown
78
83
* @param OrderTaxDetailsItemInterface $itemTaxDetail
79
- * @param float $taxRatio
84
+ * @param float $taxRatio
80
85
* @return array
81
86
*/
82
- private function aggregateTaxes ($ taxClassBreakdown , OrderTaxDetailsItemInterface $ itemTaxDetail , $ taxRatio )
83
- {
87
+ private function aggregateTaxes (
88
+ array $ taxClassBreakdown ,
89
+ OrderTaxDetailsItemInterface $ itemTaxDetail ,
90
+ float $ taxRatio
91
+ ): array {
84
92
$ itemAppliedTaxes = $ itemTaxDetail ->getAppliedTaxes ();
85
93
foreach ($ itemAppliedTaxes as $ itemAppliedTax ) {
86
94
$ taxAmount = $ itemAppliedTax ->getAmount () * $ taxRatio ;
0 commit comments