Skip to content

Commit 57dfd6f

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

File tree

11 files changed

+60
-58
lines changed

11 files changed

+60
-58
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,6 @@ 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-
342338
type CartItemPrices {
343339
price: Money!
344340
row_total: Money!

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,22 @@ public function resolve(
121121
*/
122122
private function getShippingDiscountDetails(CreditmemoInterface $creditmemoModel, $orderModel)
123123
{
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 ?
124+
$creditmemoShippingAmount = (float)$creditmemoModel->getShippingAmount();
125+
$orderShippingAmount = (float)$orderModel->getShippingAmount();
126+
$calculatedShippingRatio = (float)$creditmemoShippingAmount != 0 && $orderShippingAmount != 0 ?
129127
($creditmemoShippingAmount / $orderShippingAmount) : 0;
130128
$orderShippingDiscount = (float)$orderModel->getShippingDiscountAmount();
131129
$calculatedCreditmemoShippingDiscount = $orderShippingDiscount * $calculatedShippingRatio;
132-
$shippingDiscounts[] = [
133-
'amount' => [
134-
'value' => $calculatedCreditmemoShippingDiscount,
135-
'currency' => $creditmemoModel->getOrderCurrencyCode()
136-
]
137-
];
130+
131+
$shippingDiscounts = [];
132+
if ($calculatedCreditmemoShippingDiscount != 0) {
133+
$shippingDiscounts[] = [
134+
'amount' => [
135+
'value' => sprintf('%.2f', abs($calculatedCreditmemoShippingDiscount)),
136+
'currency' => $creditmemoModel->getOrderCurrencyCode()
137+
]
138+
];
139+
}
138140
return $shippingDiscounts;
139141
}
140142

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,22 @@ public function resolve(
118118
*/
119119
private function getShippingDiscountDetails(InvoiceInterface $invoiceModel, OrderInterface $orderModel)
120120
{
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 ?
121+
$invoiceShippingAmount = (float)$invoiceModel->getShippingAmount();
122+
$orderShippingAmount = (float)$orderModel->getShippingAmount();
123+
$calculatedShippingRatioFromOriginal = $invoiceShippingAmount != 0 && $orderShippingAmount != 0 ?
127124
( $invoiceShippingAmount / $orderShippingAmount) : 0;
128125
$orderShippingDiscount = (float)$orderModel->getShippingDiscountAmount();
129126
$calculatedInvoiceShippingDiscount = $orderShippingDiscount * $calculatedShippingRatioFromOriginal;
130-
131-
$shippingDiscounts[] =
132-
[
133-
'amount' => [
134-
'value' => $calculatedInvoiceShippingDiscount,
135-
'currency' => $invoiceModel->getOrderCurrencyCode()
136-
]
137-
];
127+
$shippingDiscounts = [];
128+
if ($calculatedInvoiceShippingDiscount != 0) {
129+
$shippingDiscounts[] =
130+
[
131+
'amount' => [
132+
'value' => sprintf('%.2f', abs($calculatedInvoiceShippingDiscount)),
133+
'currency' => $invoiceModel->getOrderCurrencyCode()
134+
]
135+
];
136+
}
138137
return $shippingDiscounts;
139138
}
140139

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ type ShippingHandling @doc(description: "The Shipping handling details") {
162162
discounts: [ShippingDiscount] @doc(description: "The applied discounts to the shipping")
163163
}
164164

165+
type ShippingDiscount @doc(description:"Defines an individual shipping discount. This discount can be applied to shipping.") {
166+
amount: Money! @doc(description:"The amount of the discount")
167+
}
168+
165169
type OrderShipment @doc(description: "Order shipment details") {
166170
id: ID! @doc(description: "The unique ID of the shipment")
167171
number: String! @doc(description: "The sequential credit shipment number")

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testSingleInvoiceForLoggedInCustomerQuery()
9494
'currency' => 'USD'
9595
],
9696
'taxes' => [],
97-
// 'discounts' => []
97+
'discounts' => []
9898
],
9999
'taxes' => [],
100100
'discounts' => [],
@@ -174,7 +174,7 @@ public function testMultipleInvoiceForLoggedInCustomerQuery()
174174
'currency' => 'USD'
175175
],
176176
'taxes' => [],
177-
// 'discounts' => [],
177+
'discounts' => [],
178178
],
179179
'taxes' => [],
180180
'discounts' => [],
@@ -228,7 +228,7 @@ public function testMultipleInvoiceForLoggedInCustomerQuery()
228228
'currency' => 'USD'
229229
],
230230
'taxes' => [],
231-
// 'discounts' => [],
231+
'discounts' => [],
232232
],
233233
'taxes' => [],
234234
'discounts' => [],
@@ -466,12 +466,9 @@ private function assertTotalsAndShippingWithTaxesAndDiscounts(array $customerOrd
466466
'rate' => 7.5
467467
]
468468
],
469-
// 'discounts'=> [
470-
// 0 => [
471-
// 'amount'=>['value' => 0.07, 'currency'=> 'USD'],
472-
// 'label' => 'Discount Label for 10% off'
473-
// ]
474-
// ],
469+
'discounts'=> [
470+
0 => ['amount'=>['value' => 1, 'currency'=> 'USD']]
471+
],
475472
]
476473
];
477474
$this->assertResponseFields($customerOrderItemTotal, $assertionMap);
@@ -509,12 +506,8 @@ private function assertTotalsAndShippingWithTaxesAndDiscountsForOneQty(array $cu
509506
'rate' => 7.5
510507
]
511508
],
512-
// 'discounts'=> [
513-
// 0 => [
514-
// 'amount'=>['value' => 0.07, 'currency'=> 'USD'],
515-
// 'label' => 'Discount Label for 10% off'
516-
// ]
517-
// ],
509+
'discounts'=> [['amount'=>['value' => 1, 'currency'=> 'USD']]
510+
],
518511
]
519512
];
520513
$this->assertResponseFields($customerOrderItemTotal, $assertionMap);
@@ -827,7 +820,7 @@ private function getCustomerInvoicesBasedOnOrderNumber($orderNumber): array
827820
amount_excluding_tax{value currency}
828821
total_amount{value currency}
829822
taxes {amount{value} title rate}
830-
# discounts {amount{value currency} label}
823+
discounts {amount{value currency}}
831824
}
832825
}
833826
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ private function assertTotalsWithTaxesAndDiscounts(array $customerOrderItemTotal
186186
'amount_excluding_tax' => ['value' => 20],
187187
'total_amount' => ['value' => 20, 'currency' =>'USD'],
188188
'discounts' => [
189-
0 => ['amount'=>['value'=> 2, 'currency' =>'USD'],
190-
'label' => 'Discount Label for 10% off'
191-
]
189+
0 => ['amount'=>['value'=> 2, 'currency' =>'USD']]
192190
],
193191
'taxes'=> [
194192
0 => [
@@ -271,9 +269,7 @@ private function assertTotalsWithTaxesAndDiscountsWithTwoRules(array $customerOr
271269
'amount_excluding_tax' => ['value' => 20],
272270
'total_amount' => ['value' => 20, 'currency' =>'USD'],
273271
'discounts' => [
274-
0 => ['amount'=>['value'=> 2, 'currency' =>'USD'],
275-
'label' => 'Discount Label for 10% off'
276-
]
272+
0 => ['amount'=>['value'=> 2, 'currency' =>'USD']]
277273
],
278274
'taxes'=> [
279275
0 => [
@@ -1245,7 +1241,7 @@ private function getCustomerOrderQuery($orderNumber): array
12451241
amount_excluding_tax{value}
12461242
total_amount{value currency}
12471243
taxes {amount{value} title rate}
1248-
discounts {amount{value currency} label}
1244+
discounts {amount{value currency}}
12491245
}
12501246
12511247
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ private function assertTotalsOnBundleProductWithTaxesAndDiscounts(array $custome
189189
'amount_excluding_tax' => ['value' => 20],
190190
'total_amount' => ['value' => 20],
191191
'discounts' => [
192-
0 => ['amount'=>['value'=> 2],
193-
'label' => 'Discount Label for 10% off'
194-
]
192+
0 => ['amount'=>['value'=> 2]]
195193
],
196194
'taxes'=> [
197195
0 => [
@@ -266,7 +264,7 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
266264
amount_including_tax{value}
267265
amount_excluding_tax{value}
268266
total_amount{value}
269-
discounts{amount{value} label}
267+
discounts{amount{value}}
270268
taxes {amount{value} title rate}
271269
}
272270
discounts {amount{value currency} label}

dev/tests/integration/testsuite/Magento/GraphQl/Sales/_files/order_with_totals.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@
5959
->setState(Order::STATE_PROCESSING)
6060
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING))
6161
->setSubtotal(110)
62-
->setOrderCurrencyCode("USD")
6362
->setShippingAmount(10.0)
6463
->setBaseShippingAmount(10.0)
6564
->setTaxAmount(5.0)
6665
->setGrandTotal(100)
6766
->setBaseSubtotal(100)
6867
->setBaseGrandTotal(100)
68+
->setOrderCurrencyCode("USD")
69+
->setBaseCurrencyCode('USD')
6970
->setCustomerIsGuest(false)
7071
->setCustomerId(1)
7172
->setCustomerEmail('[email protected]')

dev/tests/integration/testsuite/Magento/GraphQl/Sales/_files/orders_with_customer.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
'state' => \Magento\Sales\Model\Order::STATE_NEW,
3131
'status' => 'processing',
3232
'order_currency_code' =>'USD',
33+
'base_currency_code' =>'USD',
3334
'grand_total' => 120.00,
3435
'subtotal' => 120.00,
3536
'base_grand_total' => 120.00,
@@ -40,6 +41,8 @@
4041
'increment_id' => '100000003',
4142
'state' => \Magento\Sales\Model\Order::STATE_PROCESSING,
4243
'status' => 'processing',
44+
'order_currency_code' =>'USD',
45+
'base_currency_code' =>'USD',
4346
'grand_total' => 130.00,
4447
'base_grand_total' => 130.00,
4548
'subtotal' => 130.00,
@@ -51,6 +54,8 @@
5154
'increment_id' => '100000004',
5255
'state' => \Magento\Sales\Model\Order::STATE_PROCESSING,
5356
'status' => 'closed',
57+
'order_currency_code' =>'USD',
58+
'base_currency_code' =>'USD',
5459
'grand_total' => 140.00,
5560
'base_grand_total' => 140.00,
5661
'subtotal' => 140.00,
@@ -61,6 +66,8 @@
6166
'increment_id' => '100000005',
6267
'state' => \Magento\Sales\Model\Order::STATE_COMPLETE,
6368
'status' => 'complete',
69+
'order_currency_code' =>'USD',
70+
'base_currency_code' =>'USD',
6471
'grand_total' => 150.00,
6572
'base_grand_total' => 150.00,
6673
'subtotal' => 150.00,
@@ -72,6 +79,8 @@
7279
'increment_id' => '100000006',
7380
'state' => \Magento\Sales\Model\Order::STATE_PROCESSING,
7481
'status' => 'Processing',
82+
'order_currency_code' =>'USD',
83+
'base_currency_code' =>'USD',
7584
'grand_total' => 160.00,
7685
'base_grand_total' => 160.00,
7786
'subtotal' => 160.00,
@@ -84,6 +93,7 @@
8493
'state' => \Magento\Sales\Model\Order::STATE_PROCESSING,
8594
'status' => 'Processing',
8695
'order_currency_code' =>'USD',
96+
'base_currency_code' =>'USD',
8797
'grand_total' => 180.00,
8898
'base_grand_total' => 180.00,
8999
'subtotal' => 170.00,
@@ -98,6 +108,7 @@
98108
'state' => \Magento\Sales\Model\Order::STATE_PROCESSING,
99109
'status' => 'Processing',
100110
'order_currency_code' =>'USD',
111+
'base_currency_code' =>'USD',
101112
'grand_total' => 190.00,
102113
'base_grand_total' => 190.00,
103114
'subtotal' => 180.00,
@@ -139,7 +150,6 @@
139150
->setName($product->getName())
140151
->setSku($product->getSku());
141152

142-
143153
$order->setData($orderData)
144154
->addItem($orderItem)
145155
->setCustomerIsGuest(false)

dev/tests/integration/testsuite/Magento/GraphQl/Sales/_files/two_orders_with_order_items_two_storeviews.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
->setCustomerId($customerIdFromFixture)
7979
->setCustomerEmail('[email protected]')
8080
->setOrderCurrencyCode('USD')
81+
->setBaseCurrencyCode('USD')
8182
->setBillingAddress($billingAddress)
8283
->setShippingAddress($shippingAddress)
8384
->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId())
@@ -128,6 +129,7 @@
128129
->setCustomerId($customerIdFromFixture)
129130
->setCustomerEmail('[email protected]')
130131
->setOrderCurrencyCode('USD')
132+
->setBaseCurrencyCode('USD')
131133
->setBillingAddress($billingAddress)
132134
->setShippingAddress($shippingAddress)
133135
->setStoreId($secondStore->load('fixture_second_store')->getId())

0 commit comments

Comments
 (0)