Skip to content

Commit d977db1

Browse files
committed
MC-20639: MyAccount :: Order Details :: Refund (creditMemo) Details by Order Number
1 parent 5b9608b commit d977db1

File tree

4 files changed

+143
-29
lines changed

4 files changed

+143
-29
lines changed

app/code/Magento/SalesGraphQl/Model/Resolver/CreditMemo/CreditMemoTotal.php

Lines changed: 130 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,44 @@
1313
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1414
use Magento\Sales\Api\Data\CreditmemoInterface;
1515
use Magento\Sales\Api\Data\OrderInterface;
16+
use Magento\SalesGraphQl\Model\SalesItem\ShippingTaxCalculator;
17+
use Magento\Tax\Api\OrderTaxManagementInterface;
18+
use Magento\Tax\Helper\Data as TaxHelper;
1619

1720
/**
1821
* Resolve credit memo totals information
1922
*/
2023
class CreditMemoTotal implements ResolverInterface
2124
{
25+
/**
26+
* @var TaxHelper
27+
*/
28+
private $taxHelper;
29+
30+
/**
31+
* @var OrderTaxManagementInterface
32+
*/
33+
private $orderTaxManagement;
34+
35+
/**
36+
* @var ShippingTaxCalculator
37+
*/
38+
private $shippingTaxCalculator;
39+
/**
40+
* @param OrderTaxManagementInterface $orderTaxManagement
41+
* @param TaxHelper $taxHelper
42+
* @param ShippingTaxCalculator $shippingTaxCalculator
43+
*/
44+
public function __construct(
45+
OrderTaxManagementInterface $orderTaxManagement,
46+
TaxHelper $taxHelper,
47+
ShippingTaxCalculator $shippingTaxCalculator
48+
) {
49+
$this->taxHelper = $taxHelper;
50+
$this->orderTaxManagement = $orderTaxManagement;
51+
$this->shippingTaxCalculator = $shippingTaxCalculator;
52+
}
53+
2254
/**
2355
* @inheritDoc
2456
*/
@@ -42,32 +74,109 @@ public function resolve(
4274
/** @var CreditmemoInterface $creditMemo */
4375
$creditMemo = $value['model'];
4476
$currency = $orderModel->getOrderCurrencyCode();
45-
77+
$baseCurrency = $orderModel->getBaseCurrencyCode();
4678
return [
47-
'subtotal' => [
48-
'value' => $creditMemo->getSubtotal(),
49-
'currency' => $currency
50-
],
51-
'base_grand_total' => [
52-
'value' => $creditMemo->getBaseGrandTotal(),
53-
'currency' => $currency
54-
],
55-
'grand_total' => [
56-
'value' => $creditMemo->getGrandTotal(),
57-
'currency' => $currency
58-
],
59-
'total_tax' => [
60-
'value' => $creditMemo->getTaxAmount(),
61-
'currency' => $currency
62-
],
63-
'shipping_amount' => [
64-
'value' => $creditMemo->getShippingAmount(),
65-
'currency' => $currency
79+
'base_grand_total' => ['value' => $creditMemo->getBaseGrandTotal(), 'currency' => $baseCurrency],
80+
'grand_total' => ['value' => $creditMemo->getGrandTotal(), 'currency' => $currency],
81+
'subtotal' => ['value' => $creditMemo->getSubtotal(), 'currency' => $currency],
82+
'total_tax' => ['value' => $creditMemo->getTaxAmount(), 'currency' => $currency],
83+
'total_shipping' => ['value' => $creditMemo->getShippingAmount(), 'currency' => $currency],
84+
'discounts' => $this->getDiscountDetails($creditMemo),
85+
'taxes' => $this->formatTaxes(
86+
$orderModel,
87+
$this->taxHelper->getCalculatedTaxes($creditMemo),
88+
),
89+
'shipping_handling' => [
90+
'amount_excluding_tax' => [
91+
'value' => $creditMemo->getShippingAmount() ?? 0,
92+
'currency' => $currency
93+
],
94+
'amount_including_tax' => [
95+
'value' => $creditMemo->getShippingInclTax() ?? 0,
96+
'currency' => $currency
97+
],
98+
'total_amount' => [
99+
'value' => $creditMemo->getShippingAmount() ?? 0,
100+
'currency' => $currency
101+
],
102+
'discounts' => $this->getShippingDiscountDetails($creditMemo),
103+
'taxes' => $this->formatTaxes(
104+
$orderModel,
105+
$this->shippingTaxCalculator->calculateShippingTaxes($orderModel, $creditMemo),
106+
)
66107
],
67108
'adjustment' => [
68-
'value' => $creditMemo->getAdjustment(),
109+
'value' => abs($creditMemo->getAdjustment()),
69110
'currency' => $currency
70111
],
71112
];
72113
}
114+
115+
/**
116+
* Return information about an applied discount on shipping
117+
*
118+
* @param CreditmemoInterface $creditmemo
119+
* @return array
120+
*/
121+
private function getShippingDiscountDetails(CreditmemoInterface $creditmemo)
122+
{
123+
$shippingDiscounts = [];
124+
if (!($creditmemo->getDiscountDescription() === null
125+
&& $creditmemo->getShippingDiscountTaxCompensationAmount() == 0)) {
126+
$shippingDiscounts[] =
127+
[
128+
'label' => $creditmemo->getDiscountDescription() ?? __('Discount'),
129+
'amount' => [
130+
'value' => abs($creditmemo->getShippingDiscountTaxCompensationAmount()),
131+
'currency' => $creditmemo->getOrderCurrencyCode()
132+
]
133+
];
134+
}
135+
return $shippingDiscounts;
136+
}
137+
138+
/**
139+
* Return information about an applied discount
140+
*
141+
* @param CreditmemoInterface $creditmemo
142+
* @return array
143+
*/
144+
private function getDiscountDetails(CreditmemoInterface $creditmemo)
145+
{
146+
$discounts = [];
147+
if (!($creditmemo->getDiscountDescription() === null && $creditmemo->getDiscountAmount() == 0)) {
148+
$discounts[] = [
149+
'label' => $creditmemo->getDiscountDescription() ?? __('Discount'),
150+
'amount' => [
151+
'value' => abs($creditmemo->getDiscountAmount()),
152+
'currency' => $creditmemo->getOrderCurrencyCode()
153+
]
154+
];
155+
}
156+
return $discounts;
157+
}
158+
159+
/**
160+
* Format applied taxes
161+
*
162+
* @param OrderInterface $order
163+
* @param array $appliedTaxes
164+
* @return array
165+
*/
166+
private function formatTaxes(OrderInterface $order, array $appliedTaxes)
167+
{
168+
$taxes = [];
169+
foreach ($appliedTaxes as $appliedTax) {
170+
$appliedTaxesArray = [
171+
'rate' => $appliedTax['percent'] ?? 0,
172+
'title' => $appliedTax['title'] ?? null,
173+
'amount' => [
174+
'value' => $appliedTax['tax_amount'] ?? 0,
175+
'currency' => $order->getOrderCurrencyCode()
176+
]
177+
];
178+
$taxes[] = $appliedTaxesArray;
179+
}
180+
return $taxes;
181+
}
73182
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public function resolve(
7575
/** @var InvoiceInterface $invoiceModel */
7676
$invoiceModel = $value['model'];
7777
$currency = $orderModel->getOrderCurrencyCode();
78+
$baseCurrency = $orderModel->getBaseCurrencyCode();
7879
return [
79-
'base_grand_total' => ['value' => $invoiceModel->getBaseGrandTotal(), 'currency' => $currency],
80+
'base_grand_total' => ['value' => $invoiceModel->getBaseGrandTotal(), 'currency' => $baseCurrency],
8081
'grand_total' => ['value' => $invoiceModel->getGrandTotal(), 'currency' => $currency],
8182
'subtotal' => ['value' => $invoiceModel->getSubtotal(), 'currency' => $currency],
8283
'total_tax' => ['value' => $invoiceModel->getTaxAmount(), 'currency' => $currency],

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ public function resolve(
3535
/** @var OrderInterface $order */
3636
$order = $value['model'];
3737
$currency = $order->getOrderCurrencyCode();
38+
$baseCurrency = $order->getBaseCurrencyCode();
3839

3940
return [
4041
'base_grand_total' => ['value' => $order->getBaseGrandTotal(), 'currency' => $currency],
41-
'grand_total' => ['value' => $order->getGrandTotal(), 'currency' => $currency],
42+
'grand_total' => ['value' => $order->getGrandTotal(), 'currency' => $baseCurrency],
4243
'subtotal' => ['value' => $order->getSubtotal(), 'currency' => $currency],
4344
'total_tax' => ['value' => $order->getTaxAmount(), 'currency' => $currency],
4445
'taxes' => $this->getAppliedTaxesDetails($order),

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ type InvoiceTotal @doc(description: "Contains price details from an invoice"){
169169
subtotal: Money! @doc(description: "The subtotal of the invoice, excluding shipping, discounts, and taxes")
170170
discounts: [Discount] @doc(description: "The applied discounts to the invoice")
171171
total_tax: Money! @doc(description: "The amount of tax applied to the invoice")
172-
taxes: [TaxItem] @doc(description: "The order tax details")
172+
taxes: [TaxItem] @doc(description: "The invoice tax details")
173173
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes")
174174
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency")
175175
total_shipping: Money! @doc(description: "The shipping amount for the invoice")
@@ -243,11 +243,14 @@ type BundleCreditMemoItem implements CreditMemoItemInterface {
243243
}
244244

245245
type CreditMemoTotal @doc(description: "Credit memo price details") {
246-
subtotal: Money! @doc(description: "The subtotal amount, excluding shipping, discounts, and tax")
247-
total_tax: Money! @doc(description: "The total tax amount")
248-
grand_total: Money! @doc(description: "The final total amount, including shipping and taxes")
249-
base_grand_total: Money! @doc(description: "The final total amount in the base currency")
250-
shipping_amount: Money! @doc(description: "The refunded shipping fees")
246+
subtotal: Money! @doc(description: "The subtotal of the invoice, excluding shipping, discounts, and taxes")
247+
discounts: [Discount] @doc(description: "The applied discounts to the credit memo")
248+
total_tax: Money! @doc(description: "The amount of tax applied to the credit memo")
249+
taxes: [TaxItem] @doc(description: "The credit memo tax details")
250+
grand_total: Money! @doc(description: "The final total amount, including shipping, discounts, and taxes")
251+
base_grand_total: Money! @doc(description: "The final base grand total amount in the base currency")
252+
total_shipping: Money! @doc(description: "The shipping amount for the credit memo")
253+
shipping_handling: ShippingHandling @doc(description: "Contains details about the shipping and handling costs for the credit memo")
251254
adjustment: Money! @doc(description: "An adjustment manually applied to the order")
252255
}
253256

0 commit comments

Comments
 (0)