Skip to content

Commit be73319

Browse files
committed
LYNX-892:[AC-2.4.9] Introduce OrderTotal.grand_total_excl_tax field
1 parent 625b01e commit be73319

File tree

4 files changed

+375
-16
lines changed

4 files changed

+375
-16
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function resolve(
5555
'currency' => $order->getBaseCurrencyCode()
5656
],
5757
'grand_total' => ['value' => $order->getGrandTotal(), 'currency' => $currency],
58+
'grand_total_excl_tax' => ['value' => $this->getGrandTotalExclTax($order), 'currency' => $currency],
5859
'subtotal' => ['value' => $order->getSubtotal(), 'currency' => $currency],
5960
'subtotal_incl_tax' => ['value' => $order->getSubtotalInclTax(), 'currency' => $currency],
6061
'subtotal_excl_tax' => ['value' => $order->getSubtotal(), 'currency' => $currency],
@@ -92,7 +93,7 @@ public function resolve(
9293
private function getAllAppliedTaxesOnOrders(OrderInterface $order): array
9394
{
9495
return array_map(
95-
fn($appliedTaxesData) => [
96+
fn ($appliedTaxesData) => [
9697
'title' => $appliedTaxesData->getTitle(),
9798
'percent' => $appliedTaxesData->getPercent(),
9899
'amount' => $appliedTaxesData->getAmount(),
@@ -111,7 +112,7 @@ private function getAllAppliedTaxesOnOrders(OrderInterface $order): array
111112
private function getAppliedTaxesDetails(OrderInterface $order): array
112113
{
113114
return array_map(
114-
fn($appliedTaxes) => [
115+
fn ($appliedTaxes) => [
115116
'rate' => $appliedTaxes['percent'] ?? 0,
116117
'title' => $appliedTaxes['title'] ?? null,
117118
'amount' => [
@@ -217,4 +218,17 @@ private function getShippingDiscountDetails(OrderInterface $order): array
217218
}
218219
return $shippingDiscounts;
219220
}
221+
222+
/**
223+
* Get grand total excluding tax
224+
*
225+
* @param OrderInterface $order
226+
* @return float
227+
*/
228+
private function getGrandTotalExclTax(OrderInterface $order): float
229+
{
230+
return (float) ($order->getSubtotal()
231+
+ $order->getShippingAmount()
232+
- abs((float)$order->getDiscountAmount()));
233+
}
220234
}

app/code/Magento/SalesGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ type OrderTotal @doc(description: "Contains details about the sales total amount
170170
shipping_handling: ShippingHandling @doc(description: "Details about the shipping and handling costs for the order.")
171171
subtotal_incl_tax: Money! @doc(description: "The subtotal of the order, including taxes.")
172172
subtotal_excl_tax: Money! @doc(description: "The subtotal of the order, excluding taxes.")
173+
grand_total_excl_tax: Money! @doc(description: "The grand total of the order, excluding taxes.")
173174
}
174175

175176
type Invoice @doc(description: "Contains invoice details.") {

app/code/Magento/Tax/Test/Fixture/TaxRate.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\Tax\Test\Fixture;
99

1010
use Magento\Framework\DataObject;
1111
use Magento\Tax\Api\TaxRateRepositoryInterface;
12+
use Magento\TestFramework\Fixture\Api\DataMerger;
1213
use Magento\TestFramework\Fixture\Api\ServiceFactory;
1314
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
1415

@@ -24,20 +25,19 @@ class TaxRate implements RevertibleDataFixtureInterface
2425
'zip_is_range' => null,
2526
'zip_from' => null,
2627
'zip_to' => null,
27-
'titles' => [],
28+
'titles' => []
2829
];
2930

3031
/**
31-
* @var ServiceFactory
32-
*/
33-
private ServiceFactory $serviceFactory;
34-
35-
/**
32+
* TaxRate Constructor
33+
*
3634
* @param ServiceFactory $serviceFactory
35+
* @param DataMerger $dataMerger
3736
*/
38-
public function __construct(ServiceFactory $serviceFactory)
39-
{
40-
$this->serviceFactory = $serviceFactory;
37+
public function __construct(
38+
private readonly ServiceFactory $serviceFactory,
39+
private readonly DataMerger $dataMerger
40+
) {
4141
}
4242

4343
/**
@@ -46,10 +46,13 @@ public function __construct(ServiceFactory $serviceFactory)
4646
public function apply(array $data = []): ?DataObject
4747
{
4848
$service = $this->serviceFactory->create(TaxRateRepositoryInterface::class, 'save');
49+
$data = $this->dataMerger->merge(
50+
self::DEFAULT_DATA,
51+
$data
52+
);
53+
$data['code'] = str_replace('%uniqid%', uniqid(), $data['code']);
4954

50-
return $service->execute([
51-
'taxRate' => array_merge(self::DEFAULT_DATA, $data),
52-
]);
55+
return $service->execute(['taxRate' => $data]);
5356
}
5457

5558
/**

0 commit comments

Comments
 (0)