Skip to content

Commit 23a9f92

Browse files
author
Prabhu Ram
committed
MC-20637: MyAccount :: Order Details :: Invoice Details by Order Number
- review fixes
1 parent 5c8daac commit 23a9f92

File tree

4 files changed

+32
-51
lines changed

4 files changed

+32
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function getDiscountDetails(OrderInterface $associatedOrder, InvoiceItem
145145
$discounts [] = [
146146
'label' => $associatedOrder->getDiscountDescription() ?? _('Discount'),
147147
'amount' => [
148-
'value' => $invoiceItem->getDiscountAmount() ?? 0,
148+
'value' => abs($invoiceItem->getDiscountAmount()) ?? 0,
149149
'currency' => $associatedOrder->getOrderCurrencyCode()
150150
]
151151
];

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Sales\Api\Data\InvoiceInterface;
1515
use Magento\Sales\Api\Data\OrderInterface;
1616
use Magento\Tax\Api\OrderTaxManagementInterface;
17-
use Magento\SalesGraphQl\Model\SalesItem\ShippingTaxHelper;
17+
use Magento\SalesGraphQl\Model\SalesItem\ShippingTaxCalculator;
1818
use Magento\Tax\Helper\Data as TaxHelper;
1919

2020
/**
@@ -33,23 +33,23 @@ class InvoiceTotal implements ResolverInterface
3333
private $orderTaxManagement;
3434

3535
/**
36-
* @var ShippingTaxHelper
36+
* @var ShippingTaxCalculator
3737
*/
38-
private $shippingTaxHelper;
38+
private $shippingTaxCalculator;
3939

4040
/**
4141
* @param OrderTaxManagementInterface $orderTaxManagement
4242
* @param TaxHelper $taxHelper
43-
* @param ShippingTaxHelper $shippingTaxHelper
43+
* @param ShippingTaxCalculator $shippingTaxCalculator
4444
*/
4545
public function __construct(
4646
OrderTaxManagementInterface $orderTaxManagement,
4747
TaxHelper $taxHelper,
48-
ShippingTaxHelper $shippingTaxHelper
48+
ShippingTaxCalculator $shippingTaxCalculator
4949
) {
5050
$this->taxHelper = $taxHelper;
5151
$this->orderTaxManagement = $orderTaxManagement;
52-
$this->shippingTaxHelper = $shippingTaxHelper;
52+
$this->shippingTaxCalculator = $shippingTaxCalculator;
5353
}
5454

5555
/**
@@ -102,7 +102,7 @@ public function resolve(
102102
'discounts' => $this->getShippingDiscountDetails($invoiceModel),
103103
'taxes' => $this->formatTaxes(
104104
$orderModel,
105-
$this->shippingTaxHelper->calculateShippingTaxes($orderModel, $invoiceModel),
105+
$this->shippingTaxCalculator->calculateShippingTaxes($orderModel, $invoiceModel),
106106
)
107107
]
108108
];

app/code/Magento/SalesGraphQl/Model/SalesItem/ShippingTaxHelper.php renamed to app/code/Magento/SalesGraphQl/Model/SalesItem/ShippingTaxCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Magento\Tax\Api\Data\OrderTaxDetailsItemInterface;
88
use Magento\Tax\Api\OrderTaxManagementInterface;
99

10-
class ShippingTaxHelper
10+
class ShippingTaxCalculator
1111
{
1212
/**
1313
* @var OrderTaxManagementInterface

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

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ protected function setUp(): void
3838
*/
3939
public function testSingleInvoiceForLoggedInCustomerQuery()
4040
{
41-
$response = $this->getCustomerInvoice();
41+
$response = $this->getCustomerInvoices();
4242
$expectedOrdersData = [
43-
'order_number' => '100000001',
4443
'status' => 'Processing',
4544
'grand_total' => 100.00
4645
];
@@ -103,9 +102,8 @@ public function testSingleInvoiceForLoggedInCustomerQuery()
103102
*/
104103
public function testMultipleInvoiceForLoggedInCustomerQuery()
105104
{
106-
$response = $this->getCustomerInvoice();
105+
$response = $this->getCustomerInvoices();
107106
$expectedOrdersData = [
108-
'order_number' => '100000002',
109107
'status' => 'Processing',
110108
'grand_total' => 50.00
111109
];
@@ -200,12 +198,11 @@ public function testMultipleCustomersWithInvoicesQuery()
200198
{
201199
$query =
202200
<<<QUERY
203-
query {
201+
{
204202
customer
205203
{
206204
orders {
207205
items {
208-
order_number
209206
grand_total
210207
status
211208
invoices {
@@ -248,7 +245,6 @@ public function testMultipleCustomersWithInvoicesQuery()
248245
$this->customerAuthenticationHeader->execute($currentEmail, $currentPassword)
249246
);
250247
$expectedOrdersData = [
251-
'order_number' => '100000001',
252248
'status' => 'Processing',
253249
'grand_total' => 100.00
254250
];
@@ -308,7 +304,7 @@ public function testInvoiceForCustomerWithTaxesAndDiscounts()
308304

309305
$orderNumber = $this->placeOrder($cartId);
310306
$this->prepareInvoice($orderNumber, 2);
311-
$customerOrderResponse = $this->getCustomerOrderQuery($orderNumber);
307+
$customerOrderResponse = $this->getCustomerInvoicesBasedOnOrderNumber($orderNumber);
312308
$customerOrderItem = $customerOrderResponse[0];
313309
$invoice = $customerOrderItem['invoices'][0];
314310
$this->assertEquals(3, $invoice['total']['discounts'][0]['amount']['value']);
@@ -342,9 +338,13 @@ public function testPartialInvoiceForCustomerWithTaxesAndDiscounts()
342338

343339
$orderNumber = $this->placeOrder($cartId);
344340
$this->prepareInvoice($orderNumber, 1);
345-
$customerOrderResponse = $this->getCustomerOrderQuery($orderNumber);
341+
$customerOrderResponse = $this->getCustomerInvoicesBasedOnOrderNumber($orderNumber);
346342
$customerOrderItem = $customerOrderResponse[0];
347343
$invoice = $customerOrderItem['invoices'][0];
344+
$invoiceItem = $invoice['items'][0];
345+
$this->assertEquals(1, $invoiceItem['discounts'][0]['amount']['value']);
346+
$this->assertEquals('USD', $invoiceItem['discounts'][0]['amount']['currency']);
347+
$this->assertEquals('Discount Label for 10% off', $invoiceItem['discounts'][0]['label']);
348348
$this->assertEquals(2, $invoice['total']['discounts'][0]['amount']['value']);
349349
$this->assertEquals('USD', $invoice['total']['discounts'][0]['amount']['currency']);
350350
$this->assertEquals(
@@ -356,6 +356,8 @@ public function testPartialInvoiceForCustomerWithTaxesAndDiscounts()
356356
}
357357

358358
/**
359+
* Prepare invoice for the order
360+
*
359361
* @param string $orderNumber
360362
* @param int|null $qty
361363
*/
@@ -737,7 +739,7 @@ private function placeOrder(string $cartId): string
737739
* @param string $orderNumber
738740
* @return array
739741
*/
740-
private function getCustomerOrderQuery($orderNumber): array
742+
private function getCustomerInvoicesBasedOnOrderNumber($orderNumber): array
741743
{
742744
$query =
743745
<<<QUERY
@@ -747,29 +749,8 @@ private function getCustomerOrderQuery($orderNumber): array
747749
orders(filter:{number:{eq:"{$orderNumber}"}}) {
748750
total_count
749751
items {
750-
id
751-
number
752-
order_date
753-
status
754-
items{product_name product_sku quantity_ordered discounts {amount{value currency} label}}
755-
total {
756-
base_grand_total{value currency}
757-
grand_total{value currency}
758-
total_tax{value currency}
759-
subtotal { value currency }
760-
taxes {amount{value currency} title rate}
761-
discounts {amount{value currency} label}
762-
total_shipping{value currency}
763-
shipping_handling
764-
{
765-
amount_including_tax{value}
766-
amount_excluding_tax{value}
767-
total_amount{value currency}
768-
taxes {amount{value} title rate}
769-
discounts {amount{value currency} label}
770-
}
771-
}
772752
invoices {
753+
items{product_sale_price{value currency} quantity_invoiced discounts {amount{value currency} label}}
773754
total {
774755
base_grand_total{value currency}
775756
grand_total{value currency}
@@ -810,33 +791,33 @@ private function getCustomerOrderQuery($orderNumber): array
810791
private function assertOrdersData($response, $expectedOrdersData): void
811792
{
812793
$actualData = $response['customer']['orders']['items'][0];
813-
$this->assertEquals(
814-
$expectedOrdersData['order_number'],
815-
$actualData['order_number'],
816-
"order_number is different than the expected for order - " . $expectedOrdersData['order_number']
817-
);
818794
$this->assertEquals(
819795
$expectedOrdersData['grand_total'],
820796
$actualData['grand_total'],
821-
"grand_total is different than the expected for order - " . $expectedOrdersData['order_number']
797+
"grand_total is different than the expected for order"
822798
);
823799
$this->assertEquals(
824800
$expectedOrdersData['status'],
825801
$actualData['status'],
826-
"status is different than the expected for order - " . $expectedOrdersData['order_number']
802+
"status is different than the expected for order"
827803
);
828804
}
829805

830-
private function getCustomerInvoice(): array
806+
/**
807+
* Get invoices for the customer
808+
*
809+
* @return array
810+
* @throws \Magento\Framework\Exception\AuthenticationException
811+
*/
812+
private function getCustomerInvoices(): array
831813
{
832814
$query =
833815
<<<QUERY
834-
query {
816+
{
835817
customer
836818
{
837819
orders {
838820
items {
839-
order_number
840821
grand_total
841822
status
842823
invoices {

0 commit comments

Comments
 (0)