Skip to content

Commit f8ed9a6

Browse files
committed
LYNX-697: Deliver subtotals fields in placeOrder mutation
1 parent ea407a5 commit f8ed9a6

File tree

3 files changed

+144
-3
lines changed

3 files changed

+144
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

@@ -41,6 +41,8 @@ public function resolve(
4141
'base_grand_total' => ['value' => $order->getBaseGrandTotal(), 'currency' => $baseCurrency],
4242
'grand_total' => ['value' => $order->getGrandTotal(), 'currency' => $currency],
4343
'subtotal' => ['value' => $order->getSubtotal(), 'currency' => $currency],
44+
'subtotal_incl_tax' => ['value' => $order->getSubtotalInclTax(), 'currency' => $currency],
45+
'subtotal_excl_tax' => ['value' => $order->getSubtotal(), 'currency' => $currency],
4446
'total_tax' => ['value' => $order->getTaxAmount(), 'currency' => $currency],
4547
'taxes' => $this->getAppliedTaxesDetails($order),
4648
'discounts' => $this->getDiscountDetails($order),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,16 @@ type TaxItem @doc(description: "Contains tax item details.") {
160160
}
161161

162162
type OrderTotal @doc(description: "Contains details about the sales total amounts used to calculate the final price.") {
163-
subtotal: Money! @doc(description: "The subtotal of the order, excluding shipping, discounts, and taxes.")
163+
subtotal: Money! @doc(description: "The subtotal of the order, excluding shipping, discounts, and taxes.") @deprecated(reason: "Use subtotal_excl_tax field instead")
164164
discounts: [Discount] @doc(description: "The applied discounts to the order.")
165165
total_tax: Money! @doc(description: "The amount of tax applied to the order.")
166166
taxes: [TaxItem] @doc(description: "The order tax details.")
167167
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes.")
168168
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency.")
169169
total_shipping: Money! @doc(description: "The shipping amount for the order.")
170170
shipping_handling: ShippingHandling @doc(description: "Details about the shipping and handling costs for the order.")
171+
subtotal_incl_tax: Money! @doc(description: "The subtotal of the order, including taxes.")
172+
subtotal_excl_tax: Money! @doc(description: "The subtotal of the order, excluding taxes.")
171173
}
172174

173175
type Invoice @doc(description: "Contains invoice details.") {
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Sales;
9+
10+
use Exception;
11+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
12+
use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture;
13+
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
14+
use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture;
15+
use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture;
16+
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
17+
use Magento\Customer\Test\Fixture\Customer as CustomerFixture;
18+
use Magento\Framework\Exception\AuthenticationException;
19+
use Magento\Framework\Exception\LocalizedException;
20+
use Magento\Integration\Api\CustomerTokenServiceInterface;
21+
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
22+
use Magento\Quote\Test\Fixture\CustomerCart as CustomerCartFixture;
23+
use Magento\Sales\Api\Data\OrderInterface;
24+
use Magento\TestFramework\Fixture\DataFixture;
25+
use Magento\TestFramework\Fixture\DataFixtureStorage;
26+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
27+
use Magento\TestFramework\Helper\Bootstrap;
28+
use Magento\TestFramework\TestCase\GraphQlAbstract;
29+
30+
/**
31+
* Test coverage for customerOrders.item.total.subtotal_incl_tax and subtotal_excl_tax
32+
*/
33+
class CustomerOrdersSubtotalFieldsTest extends GraphQlAbstract
34+
{
35+
/**
36+
* @var CustomerTokenServiceInterface
37+
*/
38+
private $customerTokenService;
39+
40+
/**
41+
* @var DataFixtureStorage
42+
*/
43+
private $fixtures;
44+
45+
/**
46+
* @return void
47+
* @throws LocalizedException
48+
*/
49+
protected function setUp(): void
50+
{
51+
$this->customerTokenService = Bootstrap::getObjectManager()->get(CustomerTokenServiceInterface::class);
52+
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
53+
}
54+
55+
/**
56+
* @throws Exception
57+
*/
58+
#[
59+
DataFixture(ProductFixture::class, as: 'product'),
60+
DataFixture(CustomerFixture::class, as: 'customer'),
61+
DataFixture(CustomerCartFixture::class, ['customer_id' => '$customer.id$'], as: 'quote'),
62+
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$quote.id$', 'product_id' => '$product.id$']),
63+
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$quote.id$']),
64+
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$quote.id$']),
65+
DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']),
66+
DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']),
67+
DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order')
68+
]
69+
public function testOrdersSubtotalFields(): void
70+
{
71+
/** @var OrderInterface $order */
72+
$order = $this->fixtures->get('order');
73+
74+
self::assertEquals(
75+
[
76+
'customer' => [
77+
'orders' => [
78+
'items' => [
79+
[
80+
'total' => [
81+
'subtotal_incl_tax' => ['value' => $order->getSubtotalInclTax()],
82+
'subtotal_excl_tax' => ['value' => $order->getSubtotal()]
83+
]
84+
]
85+
]
86+
]
87+
]
88+
],
89+
$this->graphQlQuery(
90+
$this->getCustomerOrdersQuery(),
91+
[],
92+
'',
93+
$this->getCustomerAuthHeaders($this->fixtures->get('customer')->getEmail())
94+
)
95+
);
96+
}
97+
98+
/**
99+
* Returns the header with customer token for GQL Mutation
100+
*
101+
* @param string $email
102+
* @return array
103+
* @throws AuthenticationException
104+
*/
105+
private function getCustomerAuthHeaders(string $email): array
106+
{
107+
$customerToken = $this->customerTokenService->createCustomerAccessToken($email, 'password');
108+
return ['Authorization' => 'Bearer ' . $customerToken];
109+
}
110+
111+
/**
112+
* Get customer orders query with subtotal fields
113+
*
114+
* @return string
115+
*/
116+
private function getCustomerOrdersQuery(): string
117+
{
118+
return <<<QUERY
119+
query {
120+
customer {
121+
orders {
122+
items {
123+
total {
124+
subtotal_incl_tax {
125+
value
126+
}
127+
subtotal_excl_tax {
128+
value
129+
}
130+
}
131+
}
132+
}
133+
}
134+
}
135+
QUERY;
136+
}
137+
}

0 commit comments

Comments
 (0)