Skip to content

Commit 423e257

Browse files
committed
MC-32658: MyAccount :: Order Details :: Order Details by Order Number Taxes and Discounts
- Added changes on taxes tests and code, fixed review comments
1 parent 12b8dce commit 423e257

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

app/code/Magento/SalesGraphQl/Model/Resolver/OrderTotal.php

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\GraphQl\Config\Element\Field;
1212
use Magento\Framework\GraphQl\Query\ResolverInterface;
1313
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
use Magento\Sales\Api\Data\OrderExtensionInterface;
1415
use Magento\Sales\Api\Data\OrderInterface;
1516

1617
class OrderTotal implements ResolverInterface
@@ -33,24 +34,9 @@ public function resolve(
3334
$order = $value['model'];
3435
$currency = $order->getOrderCurrencyCode();
3536
$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);
5440

5541
return [
5642
'base_grand_total' => ['value' => $order->getBaseGrandTotal(), 'currency' => $currency],
@@ -73,6 +59,46 @@ public function resolve(
7359
];
7460
}
7561

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+
76102
/**
77103
* Return information about an applied discount
78104
*

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/RetrieveOrdersByOrderNumberTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,6 @@ public function testGetMultipleCustomerOrdersQueryWithDefaultPagination()
590590
4,
591591
$customerOrderItemsInResponse[$key]['total']['shipping_handling']['total_amount']['value']
592592
);
593-
$this->assertEquals(
594-
0,
595-
$customerOrderItemsInResponse[$key]['total']['shipping_handling']['taxes'][0]['amount']['value']
596-
);
597593
$this->assertEquals(
598594
5,
599595
$customerOrderItemsInResponse[$key]['total']['total_shipping']['value']
@@ -1666,14 +1662,6 @@ private function assertTotals(array $response, int $expectedCount): void
16661662
'USD',
16671663
$response['customer']['orders']['items'][0]['total']['shipping_handling']['total_amount']['currency']
16681664
);
1669-
$this->assertEquals(
1670-
0,
1671-
$response['customer']['orders']['items'][0]['total']['taxes'][0]['amount']['value']
1672-
);
1673-
$this->assertEquals(
1674-
'USD',
1675-
$response['customer']['orders']['items'][0]['total']['taxes'][0]['amount']['currency']
1676-
);
16771665
}
16781666
}
16791667

0 commit comments

Comments
 (0)