Skip to content

Commit 8b4cc81

Browse files
committed
MC-32658: MyAccount :: Order Details :: Order Details by Order Number Taxes and Discounts
- Added changes to taxes and discounts on order total
1 parent 9438a62 commit 8b4cc81

File tree

4 files changed

+90
-92
lines changed

4 files changed

+90
-92
lines changed

app/code/Magento/SalesGraphQl/Model/Resolver/OrderItem/DataProvider.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,23 @@ function ($orderItem) {
214214
*
215215
* @param OrderInterface $associatedOrder
216216
* @param OrderItemInterface $orderItem
217-
* @return array|null
217+
* @return array
218218
*/
219-
private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemInterface $orderItem)
219+
private function getDiscountDetails(OrderInterface $associatedOrder, OrderItemInterface $orderItem) : array
220220
{
221221
if ($associatedOrder->getDiscountDescription() === null && $orderItem->getDiscountAmount() == 0
222222
&& $associatedOrder->getDiscountAmount() == 0
223223
) {
224-
return null;
224+
$discounts = [];
225+
} else {
226+
$discounts [] = [
227+
'label' => $associatedOrder->getDiscountDescription() ?? "null",
228+
'amount' => [
229+
'value' => $orderItem->getDiscountAmount() ?? 0,
230+
'currency' => $associatedOrder->getOrderCurrencyCode()
231+
]
232+
];
225233
}
226-
227-
$discounts [] = [
228-
'label' => $associatedOrder->getDiscountDescription() ?? "null",
229-
'amount' => [
230-
'value' => $orderItem->getDiscountAmount() ?? 0,
231-
'currency' => $associatedOrder->getOrderCurrencyCode()
232-
]
233-
];
234234
return $discounts;
235235
}
236236
}

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

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
12-
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1312
use Magento\Framework\GraphQl\Query\ResolverInterface;
1413
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15-
use Magento\GraphQl\Model\Query\ContextInterface;
1614
use Magento\Sales\Model\Order;
1715

1816
class OrderTotal implements ResolverInterface
@@ -27,12 +25,7 @@ public function resolve(
2725
array $value = null,
2826
array $args = null
2927
) {
30-
/** @var ContextInterface $context */
31-
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
32-
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
33-
}
34-
35-
if (!isset($value['model']) && !($value['model'] instanceof Order)) {
28+
if (!isset($value['model']) || !($value['model'] instanceof Order)) {
3629
throw new LocalizedException(__('"model" value should be specified'));
3730
}
3831

@@ -45,17 +38,21 @@ public function resolve(
4538
$appliedShippingTaxesForItemsData[] = [];
4639
if (!empty($appliedTaxesForItems)) {
4740
foreach ($appliedTaxesForItems as $key => $appliedTaxForItem) {
41+
$index = $key;
4842
$appliedTaxType = $appliedTaxForItem->getType();
4943
$taxLineItems = $appliedTaxForItem->getAppliedTaxes();
50-
foreach ($taxLineItems as $taxLineItem) {
44+
foreach ($taxLineItems as $new => $taxLineItem) {
45+
$allAppliedTaxesForItemsData[$key][$index]['title'] = $taxLineItem->getDataByKey('title');
46+
$allAppliedTaxesForItemsData[$key][$index]['percent'] = $taxLineItem->getDataByKey('percent');
47+
$allAppliedTaxesForItemsData[$key][$index]['amount'] = $taxLineItem->getDataByKey('amount');
5148
if ($appliedTaxType === "shipping") {
52-
$appliedShippingTaxesForItemsData[$key]['title'] = $taxLineItem->getDataByKey('title');
53-
$appliedShippingTaxesForItemsData[$key]['percent'] = $taxLineItem->getDataByKey('percent');
54-
$appliedShippingTaxesForItemsData[$key]['amount'] = $taxLineItem->getDataByKey('amount');
49+
$appliedShippingTaxesForItemsData[$key][$index]['title'] =
50+
$taxLineItem->getDataByKey('title');
51+
$appliedShippingTaxesForItemsData[$key][$index]['percent'] =
52+
$taxLineItem->getDataByKey('percent');
53+
$appliedShippingTaxesForItemsData[$key][$index]['amount'] =
54+
$taxLineItem->getDataByKey('amount');
5555
}
56-
$allAppliedTaxesForItemsData[$key]['title'] = $taxLineItem->getDataByKey('title');
57-
$allAppliedTaxesForItemsData[$key]['percent'] = $taxLineItem->getDataByKey('percent');
58-
$allAppliedTaxesForItemsData[$key]['amount'] = $taxLineItem->getDataByKey('amount');
5956
}
6057
}
6158
}
@@ -69,12 +66,14 @@ public function resolve(
6966
'discounts' => $this->getDiscountDetails($order),
7067
'total_shipping' => ['value' => $order->getShippingAmount(), 'currency' => $currency],
7168
'shipping_handling' => [
72-
'amount_excluding_tax' => ['value' => $order->getShippingAmount(), 'currency' => $order->getOrderCurrencyCode()],
69+
'amount_excluding_tax' => [
70+
'value' => $order->getShippingAmount(),
71+
'currency' => $order->getOrderCurrencyCode()
72+
],
7373
'amount_including_tax' => ['value' => $order->getShippingInclTax(), 'currency' => $currency],
7474
'total_amount' => ['value' => $order->getBaseShippingAmount(), 'currency' => $currency],
7575
'taxes' => $this->getAppliedTaxesDetails($order, $appliedShippingTaxesForItemsData),
7676
'discounts' => $this->getShippingDiscountDetails($order),
77-
7877
]
7978
];
8079
return $total;
@@ -84,44 +83,44 @@ public function resolve(
8483
* Returns information about an applied discount
8584
*
8685
* @param Order $order
87-
* @return array|null
86+
* @return array
8887
*/
8988
private function getShippingDiscountDetails(Order $order)
9089
{
9190
if ($order->getDiscountDescription() === null && $order->getShippingDiscountAmount() == 0) {
92-
return null;
91+
$shippingDiscounts = [ ];
92+
} else {
93+
$shippingDiscounts [] =
94+
[
95+
'label' => $order->getDiscountDescription() ?? "null",
96+
'amount' => [
97+
'value' => $order->getShippingDiscountAmount(),
98+
'currency' => $order->getOrderCurrencyCode()
99+
]
100+
];
93101
}
94-
95-
$shippingDiscounts [] =
96-
[
97-
'label' => $order->getDiscountDescription() ?? "null",
98-
'amount' => [
99-
'value' => $order->getShippingDiscountAmount(),
100-
'currency' => $order->getOrderCurrencyCode()
101-
]
102-
];
103102
return $shippingDiscounts;
104103
}
105104

106105
/**
107106
* Returns information about an applied discount
108107
*
109108
* @param Order $order
110-
* @return array|null
109+
* @return array
111110
*/
112111
private function getDiscountDetails(Order $order)
113112
{
114113
if ($order->getDiscountDescription() === null && $order->getDiscountAmount() == 0) {
115-
return null;
114+
$discounts = [];
115+
} else {
116+
$discounts [] = [
117+
'label' => $order->getDiscountDescription() ?? "null",
118+
'amount' => [
119+
'value' => $order->getDiscountAmount(),
120+
'currency' => $order->getOrderCurrencyCode()
121+
]
122+
];
116123
}
117-
118-
$discounts [] = [
119-
'label' => $order->getDiscountDescription() ?? "null",
120-
'amount' => [
121-
'value' => $order->getDiscountAmount(),
122-
'currency' => $order->getOrderCurrencyCode()
123-
]
124-
];
125124
return $discounts;
126125
}
127126

@@ -130,20 +129,32 @@ private function getDiscountDetails(Order $order)
130129
*
131130
* @param Order $order
132131
* @param array $appliedTaxesArray
133-
* @return array|null
132+
* @return array
134133
*/
135134
private function getAppliedTaxesDetails(Order $order, array $appliedTaxesArray): array
136135
{
137136
if (empty($appliedTaxesArray)) {
138-
$taxes [] = null;
137+
$taxes [] = [];
139138
} else {
140-
foreach ($appliedTaxesArray as $appliedTaxes) {
141-
$taxes[] = [
142-
'rate' => $appliedTaxes['percent'] ?? 0,
143-
'title' => $appliedTaxes['title'] ?? " ",
144-
'amount' => ['value' => $appliedTaxes['amount'] ?? 0 , 'currency' => $order->getOrderCurrencyCode()
145-
]
146-
];
139+
foreach ($appliedTaxesArray as $key => $appliedTaxes) {
140+
if (empty($appliedTaxes[$key])) {
141+
$taxes [] = [
142+
'title' => $appliedTaxes[$key]['title'] ?? " ",
143+
'amount' => [
144+
'value' => $appliedTaxes[$key]['amount'] ?? 0,
145+
'currency' => $order->getOrderCurrencyCode()
146+
]
147+
];
148+
} else {
149+
$taxes [] = [
150+
'rate' => $appliedTaxes[$key]['percent'] ?? 0,
151+
'title' => $appliedTaxes[$key]['title'] ?? " ",
152+
'amount' => [
153+
'value' => $appliedTaxes[$key]['amount'] ?? 0,
154+
'currency' => $order->getOrderCurrencyCode()
155+
]
156+
];
157+
}
147158
}
148159
/** @var array $taxes */
149160
return $taxes;

app/code/Magento/SalesGraphQl/Model/SalesTotalAmountTypeResolver.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,19 @@ type OrderItemOption @doc(description: "Represents order item options like selec
105105
value: String! @doc(description: "The value of the option")
106106
}
107107

108-
interface SalesTotalAmountInterface @doc(description: "Sales total details") @typeResolver(class: "Magento\\SalesGraphQl\\Model\\SalesTotalAmountTypeResolver") {
109-
subtotal: Money! @doc(description: "The subtotal of the order, excluding shipping, discounts, and taxes")
110-
discounts: [Discount] @doc(description: "The applied discounts to the order")
111-
total_tax: Money! @doc(description: "The amount of tax applied to the order")
112-
taxes: [TaxItem] @doc(description: "The order tax details")
113-
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes")
114-
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency")
115-
}
116-
117108
type TaxItem @doc(description: "The tax item details") {
118109
amount: Money! @doc(description: "The amount of tax applied to the item")
119110
title: String! @doc(description: "A title that describes the tax")
120111
rate: Float @doc(description: "The rate used to calculate the tax")
121112
}
122113
123-
type OrderTotal implements SalesTotalAmountInterface @doc(description: "Contains details about the sales total amounts used to calculate the final price") {
114+
type OrderTotal @doc(description: "Contains details about the sales total amounts used to calculate the final price") {
115+
subtotal: Money! @doc(description: "The subtotal of the order, excluding shipping, discounts, and taxes")
116+
discounts: [Discount] @doc(description: "The applied discounts to the order")
117+
total_tax: Money! @doc(description: "The amount of tax applied to the order")
118+
taxes: [TaxItem] @doc(description: "The order tax details")
119+
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes")
120+
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency")
124121
total_shipping: Money! @doc(description: "The shipping amount for the order")
125122
shipping_handling: ShippingHandling @doc(description: "Contains details about the shipping and handling costs for the order")
126123
}
@@ -151,7 +148,13 @@ type BundleInvoiceItem implements InvoiceItemInterface{
151148
bundle_options: [ItemSelectedBundleOption] @doc(description: "A list of bundle options that are assigned to the bundle product") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\BundleOptions")
152149
}
153150

154-
type InvoiceTotal implements SalesTotalAmountInterface @doc(description: "Invoice total amount details") {
151+
type InvoiceTotal {
152+
subtotal: Money! @doc(description: "The subtotal of the order, excluding shipping, discounts, and taxes")
153+
discounts: [Discount] @doc(description: "The applied discounts to the order")
154+
total_tax: Money! @doc(description: "The amount of tax applied to the order")
155+
taxes: [TaxItem] @doc(description: "The order tax details")
156+
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes")
157+
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency")
155158
total_shipping: Money! @doc(description: "The shipping amount for the invoice")
156159
shipping_handling: ShippingHandling @doc(description: "Contains details about the shipping and handling costs for the invoice")
157160
}
@@ -221,8 +224,13 @@ type CreditMemoItem @doc(description: "Credit memo item details") {
221224
quantity_invoiced: Float @doc(description: "The number of invoiced items")
222225
}
223226

224-
type CreditMemoTotal implements SalesTotalAmountInterface @doc(description: "Contains credit memo price details") {
225-
227+
type CreditMemoTotal @doc(description: "Contains credit memo price details") {
228+
subtotal: Money! @doc(description: "The subtotal of the order, excluding shipping, discounts, and taxes")
229+
discounts: [Discount] @doc(description: "The applied discounts to the order")
230+
total_tax: Money! @doc(description: "The amount of tax applied to the order")
231+
taxes: [TaxItem] @doc(description: "The order tax details")
232+
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes")
233+
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency")
226234
}
227235

228236
enum CheckoutUserInputErrorCodes {

0 commit comments

Comments
 (0)