Skip to content

Commit a9538f0

Browse files
committed
MC-20639: MyAccount :: Order Details :: Refund (creditMemo) Details by Order Number
- fix base currency
1 parent bfaffad commit a9538f0

File tree

6 files changed

+54
-41
lines changed

6 files changed

+54
-41
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ type Discount @doc(description:"Defines an individual discount. A discount can b
335335
label: String! @doc(description:"A description of the discount")
336336
}
337337

338+
type ShippingDiscount @doc(description:"Defines an individual shipping discount. This discount can be applied to shipping.") {
339+
amount: Money! @doc(description:"The amount of the discount")
340+
}
341+
338342
type CartItemPrices {
339343
price: Money!
340344
row_total: Money!

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Magento\Sales\Api\Data\CreditmemoItemInterface;
1717
use Magento\Sales\Api\Data\OrderInterface;
1818
use Magento\Sales\Api\Data\OrderItemInterface;
19-
use Magento\SalesGraphQl\Model\Resolver\OrderItem\DataProvider as OrderItemProvider;
19+
use Magento\SalesGraphQl\Model\OrderItem\DataProvider as OrderItemProvider;
2020

2121
/**
2222
* Resolve credit memos items data

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function resolve(
9999
'value' => $creditMemo->getShippingAmount() ?? 0,
100100
'currency' => $currency
101101
],
102-
'discounts' => $this->getShippingDiscountDetails($creditMemo),
102+
'discounts' => $this->getShippingDiscountDetails($creditMemo, $orderModel),
103103
'taxes' => $this->formatTaxes(
104104
$orderModel,
105105
$this->shippingTaxCalculator->calculateShippingTaxes($orderModel, $creditMemo),
@@ -115,23 +115,26 @@ public function resolve(
115115
/**
116116
* Return information about an applied discount on shipping
117117
*
118-
* @param CreditmemoInterface $creditmemo
118+
* @param CreditmemoInterface $creditmemoModel
119+
* @param OrderInterface $orderModel
119120
* @return array
120121
*/
121-
private function getShippingDiscountDetails(CreditmemoInterface $creditmemo)
122+
private function getShippingDiscountDetails(CreditmemoInterface $creditmemoModel, $orderModel)
122123
{
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-
}
124+
$creditmemoShippingAmount = (float) $this->taxHelper->applyTaxAfterDiscount() ?
125+
$creditmemoModel->getShippingAmount() : $creditmemoModel->getShippingInclTax();
126+
$orderShippingAmount = (float)$this->taxHelper->applyTaxAfterDiscount() ?
127+
$orderModel->getShippingAmount() : $orderModel->getShippingInclTax();
128+
$calculatedShippingRatio = (float)$creditmemoShippingAmount > 0 && $orderShippingAmount > 0 ?
129+
($creditmemoShippingAmount / $orderShippingAmount) : 0;
130+
$orderShippingDiscount = (float)$orderModel->getShippingDiscountAmount();
131+
$calculatedCreditmemoShippingDiscount = $orderShippingDiscount * $calculatedShippingRatio;
132+
$shippingDiscounts[] = [
133+
'amount' => [
134+
'value' => $calculatedCreditmemoShippingDiscount,
135+
'currency' => $creditmemoModel->getOrderCurrencyCode()
136+
]
137+
];
135138
return $shippingDiscounts;
136139
}
137140

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function resolve(
100100
'value' => $invoiceModel->getShippingAmount() ?? 0,
101101
'currency' => $currency
102102
],
103-
'discounts' => $this->getShippingDiscountDetails($invoiceModel),
103+
'discounts' => $this->getShippingDiscountDetails($invoiceModel, $orderModel),
104104
'taxes' => $this->formatTaxes(
105105
$orderModel,
106106
$this->shippingTaxCalculator->calculateShippingTaxes($orderModel, $invoiceModel),
@@ -112,23 +112,29 @@ public function resolve(
112112
/**
113113
* Return information about an applied discount on shipping
114114
*
115-
* @param InvoiceInterface $invoice
115+
* @param InvoiceInterface $invoiceModel
116+
* @param OrderInterface $invoiceModel
116117
* @return array
117118
*/
118-
private function getShippingDiscountDetails(InvoiceInterface $invoice)
119+
private function getShippingDiscountDetails(InvoiceInterface $invoiceModel, OrderInterface $orderModel)
119120
{
120-
$shippingDiscounts = [];
121-
if (!($invoice->getDiscountDescription() === null
122-
&& $invoice->getShippingDiscountTaxCompensationAmount() == 0)) {
123-
$shippingDiscounts[] =
124-
[
125-
'label' => $invoice->getDiscountDescription() ?? __('Discount'),
126-
'amount' => [
127-
'value' => abs($invoice->getShippingDiscountTaxCompensationAmount()),
128-
'currency' => $invoice->getOrderCurrencyCode()
129-
]
130-
];
131-
}
121+
// choose including or excluding depending on setting apply before or after tax;
122+
$invoiceShippingAmount = (float) $this->taxHelper->applyTaxAfterDiscount() ?
123+
$invoiceModel->getShippingAmount() : $invoiceModel->getShippingInclTax();
124+
$orderShippingAmount = (float) $this->taxHelper->applyTaxAfterDiscount() ?
125+
$orderModel->getShippingAmount() : $orderModel->getShippingInclTax();
126+
$calculatedShippingRatioFromOriginal = $invoiceShippingAmount > 0 && $orderShippingAmount > 0 ?
127+
( $invoiceShippingAmount / $orderShippingAmount) : 0;
128+
$orderShippingDiscount = (float)$orderModel->getShippingDiscountAmount();
129+
$calculatedInvoiceShippingDiscount = $orderShippingDiscount * $calculatedShippingRatioFromOriginal;
130+
131+
$shippingDiscounts[] =
132+
[
133+
'amount' => [
134+
'value' => $calculatedInvoiceShippingDiscount,
135+
'currency' => $invoiceModel->getOrderCurrencyCode()
136+
]
137+
];
132138
return $shippingDiscounts;
133139
}
134140

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ type ShippingHandling @doc(description: "The Shipping handling details") {
159159
amount_including_tax: Money @doc(description: "The shipping amount, including tax")
160160
amount_excluding_tax: Money @doc(description: "The shipping amount, excluding tax")
161161
taxes: [TaxItem] @doc(description: "Contains details about taxes applied for shipping")
162-
discounts: [Discount] @doc(description: "The applied discounts to the shipping")
162+
discounts: [ShippingDiscount] @doc(description: "The applied discounts to the shipping")
163163
}
164164

165165
type OrderShipment @doc(description: "Order shipment details") {

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/CreditmemoTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function testCreditMemoForLoggedInCustomerQuery(): void
133133
'value' => 0
134134
],
135135
'taxes' => [],
136-
// 'discounts' => [],
136+
'discounts' => [],
137137
],
138138
'adjustment' => [
139139
'value' => 1.23
@@ -234,7 +234,7 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
234234
'value' => 10
235235
],
236236
'taxes' => [],
237-
// 'discounts' => [],
237+
'discounts' => [],
238238
],
239239
'adjustment' => [
240240
'value' => 2
@@ -343,16 +343,16 @@ public function testCreditMemoForBundleProductWithTaxesAndDiscounts()
343343
],
344344
'taxes'=> [
345345
0 => [
346-
'amount'=>['value' => 0.67],
346+
'amount' => ['value' => 0.67],
347347
'title' => 'US-TEST-*-Rate-1',
348348
'rate' => 7.5
349349
]
350350
],
351-
// 'discounts' => [
352-
// 0 => ['amount'=>['value'=> 1],
353-
// 'label' => 'Discount Label for 10% off'
354-
// ]
355-
// ],
351+
'discounts' => [
352+
[
353+
'amount'=> ['value'=> 1],
354+
]
355+
],
356356
],
357357
'adjustment' => [
358358
'value' => 0
@@ -774,7 +774,7 @@ private function getCustomerOrderWithCreditMemoQuery(): array
774774
amount_excluding_tax{value}
775775
total_amount{value}
776776
taxes {amount{value} title rate}
777-
# discounts {amount{value} label}
777+
discounts {amount{value}}
778778
}
779779
adjustment {
780780
value

0 commit comments

Comments
 (0)