Skip to content

Commit fc20c9d

Browse files
committed
LYNX-699 Cannot return null for non-nullable field TaxItem.title on placeOrder GQL
1 parent 44231f7 commit fc20c9d

File tree

2 files changed

+333
-16
lines changed

2 files changed

+333
-16
lines changed

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
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
*/
66
declare(strict_types=1);
77

88
namespace Magento\SalesGraphQl\Model\Resolver;
99

1010
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\GraphQl\Config\Element\Field;
1213
use Magento\Framework\GraphQl\Query\ResolverInterface;
1314
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1415
use Magento\Sales\Api\Data\OrderInterface;
16+
use Magento\Tax\Api\OrderTaxManagementInterface;
1517

1618
/**
1719
* Resolve order totals taxes and discounts for order
1820
*/
1921
class 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

Comments
 (0)