Skip to content

Commit a8844ae

Browse files
committed
MC-32658: MyAccount :: Order Details :: Order Details by Order Number Taxes and Discounts
- Added test on bundle with taxes and discounts
1 parent 6ef2b46 commit a8844ae

File tree

1 file changed

+210
-6
lines changed

1 file changed

+210
-6
lines changed

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

Lines changed: 210 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1414
use Magento\Framework\Api\SearchCriteriaBuilder;
1515
use Magento\Framework\Exception\AuthenticationException;
16+
use Magento\GraphQl\GetCustomerAuthenticationHeader;
1617
use Magento\Integration\Api\CustomerTokenServiceInterface;
1718
use Magento\Sales\Api\OrderRepositoryInterface;
1819
use Magento\Sales\Model\Order;
19-
use Magento\TestFramework\Helper\Bootstrap;
2020
use Magento\Sales\Model\ResourceModel\Order\Collection;
21+
use Magento\TestFramework\Helper\Bootstrap;
2122
use Magento\TestFramework\TestCase\GraphQlAbstract;
22-
use Magento\GraphQl\GetCustomerAuthenticationHeader;
2323

2424
/**
2525
* Class RetrieveOrdersTest
@@ -194,14 +194,198 @@ public function testGetCustomerOrderWithBundleProduct()
194194
$this->assertEquals("Pending", $customerOrderItems['status']);
195195

196196
$bundledItemInTheOrder = $customerOrderItems['items'][0];
197-
$this->assertEquals('bundle-product-two-dropdown-options', $bundledItemInTheOrder['product_sku']);
197+
$this->assertEquals('bundle-product-two-dropdown-options-simple1-simple2', $bundledItemInTheOrder['product_sku']);
198+
$this->assertArrayHasKey('child_items', $bundledItemInTheOrder);
199+
$childItemInTheOrder = $bundledItemInTheOrder['child_items'][0];
200+
$this->assertNotEmpty($childItemInTheOrder);
201+
$this->assertEquals('simple1', $childItemInTheOrder['product_sku']);
202+
$this->deleteOrder();
203+
}
204+
205+
/**
206+
* Test customer order details with bundle products
207+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
208+
* @magentoApiDataFixture Magento/Bundle/_files/bundle_product_two_dropdown_options.php
209+
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
210+
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
211+
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
212+
*/
213+
public function testGetCustomerOrderWithBundleProductWithTaxesAndDiscounts()
214+
{
215+
$qty = 4;
216+
$bundleSku = 'bundle-product-two-dropdown-options';
217+
$simpleProductSku = 'simple2';
218+
/** @var Product $simple */
219+
$simple = $this->productRepository->get($simpleProductSku);
220+
$stockData =[
221+
StockItemInterface::QTY => 200,
222+
StockItemInterface::MANAGE_STOCK =>true,
223+
StockItemInterface::IS_IN_STOCK =>true
224+
];
225+
$simple->setQuantityAndStockStatus($stockData);
226+
$this->productRepository->save($simple);
227+
/** @var Product $bundleProduct */
228+
$bundleProduct = $this->productRepository->get($bundleSku);
229+
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
230+
$typeInstance = $bundleProduct->getTypeInstance();
231+
/** @var $option \Magento\Bundle\Model\Option */
232+
$option1 = $typeInstance->getOptionsCollection($bundleProduct)->getFirstItem();
233+
$option2 = $typeInstance->getOptionsCollection($bundleProduct)->getLastItem();
234+
$optionId1 =(int) $option1->getId();
235+
$optionId2 =(int) $option2->getId();
236+
/** @var Selection $selection */
237+
$selection1 = $typeInstance->getSelectionsCollection([$option1->getId()], $bundleProduct)->getFirstItem();
238+
$selectionId1 = (int)$selection1->getSelectionId();
239+
240+
$selection2 = $typeInstance->getSelectionsCollection([$option2->getId()], $bundleProduct)->getLastItem();
241+
$selectionId2 = (int)$selection2->getSelectionId();
242+
243+
$cartId = $this->createEmptyCart();
244+
$this->addBundleProductToCart($cartId, $qty, $bundleSku, $optionId1, $selectionId1, $optionId2, $selectionId2);
245+
$this->setBillingAddress($cartId);
246+
$shippingMethod = $this->setShippingAddress($cartId);
247+
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
248+
$this->setPaymentMethod($cartId, $paymentMethod);
249+
$orderNumber = $this->placeOrder($cartId);
250+
$customerOrderResponse = $this->getCustomerOrderQueryBundleProduct($orderNumber);
251+
252+
$customerOrderItems = $customerOrderResponse[0];
253+
$this->assertEquals("Pending", $customerOrderItems['status']);
254+
255+
$bundledItemInTheOrder = $customerOrderItems['items'][0];
256+
$this->assertEquals('bundle-product-two-dropdown-options-simple1-simple2', $bundledItemInTheOrder['product_sku']);
198257
$this->assertArrayHasKey('child_items', $bundledItemInTheOrder);
199258
$childItemInTheOrder = $bundledItemInTheOrder['child_items'][0];
200259
$this->assertNotEmpty($childItemInTheOrder);
201-
$this->assertEquals('simple-1', $childItemInTheOrder['product_sku']);
260+
$this->assertEquals('simple1', $childItemInTheOrder['product_sku']);
261+
$this->assertEquals(
262+
0,
263+
$childItemInTheOrder['discounts'][0]['amount']['value']
264+
);
265+
$this->assertEquals(
266+
'USD',
267+
$childItemInTheOrder['discounts'][0]['amount']['currency']
268+
);
269+
$this->assertEquals(
270+
'null',
271+
$childItemInTheOrder['discounts'][0]['label']
272+
);
273+
$this->assertTotalsOnBundleProductWithTaxesAndDiscounts($customerOrderItems);
202274
$this->deleteOrder();
203275
}
204276

277+
/**
278+
* Assert order totals including shipping_handling and taxes
279+
*
280+
* @param array $customerOrderItem
281+
*/
282+
private function assertTotalsOnBundleProductWithTaxesAndDiscounts(array $customerOrderItem): void
283+
{
284+
$this->assertEquals(
285+
77.4,
286+
$customerOrderItem['total']['base_grand_total']['value']
287+
);
288+
289+
$this->assertEquals(
290+
77.4,
291+
$customerOrderItem['total']['grand_total']['value']
292+
);
293+
$this->assertEquals(
294+
60,
295+
$customerOrderItem['total']['subtotal']['value']
296+
);
297+
$this->assertEquals(
298+
5.4,
299+
$customerOrderItem['total']['total_tax']['value']
300+
);
301+
302+
$this->assertEquals(
303+
20,
304+
$customerOrderItem['total']['total_shipping']['value']
305+
);
306+
$this->assertEquals(
307+
1.35,
308+
$customerOrderItem['total']['taxes'][0]['amount']['value']
309+
);
310+
$this->assertEquals(
311+
'USD',
312+
$customerOrderItem['total']['taxes'][0]['amount']['currency']
313+
);
314+
$this->assertEquals(
315+
'US-TEST-*-Rate-1',
316+
$customerOrderItem['total']['taxes'][0]['title']
317+
);
318+
$this->assertEquals(
319+
7.5,
320+
$customerOrderItem['total']['taxes'][0]['rate']
321+
);
322+
$this->assertEquals(
323+
4.05,
324+
$customerOrderItem['total']['taxes'][1]['amount']['value']
325+
);
326+
$this->assertEquals(
327+
'USD',
328+
$customerOrderItem['total']['taxes'][1]['amount']['currency']
329+
);
330+
$this->assertEquals(
331+
'US-TEST-*-Rate-1',
332+
$customerOrderItem['total']['taxes'][1]['title']
333+
);
334+
$this->assertEquals(
335+
7.5,
336+
$customerOrderItem['total']['taxes'][1]['rate']
337+
);
338+
$this->assertEquals(
339+
21.5,
340+
$customerOrderItem['total']['shipping_handling']['amount_including_tax']['value']
341+
);
342+
$this->assertEquals(
343+
20,
344+
$customerOrderItem['total']['shipping_handling']['amount_excluding_tax']['value']
345+
);
346+
$this->assertEquals(
347+
20,
348+
$customerOrderItem['total']['shipping_handling']['total_amount']['value']
349+
);
350+
351+
$this->assertEquals(
352+
1.35,
353+
$customerOrderItem['total']['shipping_handling']['taxes'][0]['amount']['value']
354+
);
355+
$this->assertEquals(
356+
'US-TEST-*-Rate-1',
357+
$customerOrderItem['total']['shipping_handling']['taxes'][0]['title']
358+
);
359+
$this->assertEquals(
360+
7.5,
361+
$customerOrderItem['total']['shipping_handling']['taxes'][0]['rate']
362+
);
363+
$this->assertEquals(
364+
2,
365+
$customerOrderItem['total']['shipping_handling']['discounts'][0]['amount']['value']
366+
);
367+
$this->assertEquals(
368+
'USD',
369+
$customerOrderItem['total']['shipping_handling']['discounts'][0]['amount']['currency']
370+
);
371+
$this->assertEquals(
372+
'null',
373+
$customerOrderItem['total']['shipping_handling']['discounts'][0]['label']
374+
);
375+
$this->assertEquals(
376+
-8,
377+
$customerOrderItem['total']['discounts'][0]['amount']['value']
378+
);
379+
$this->assertEquals(
380+
'USD',
381+
$customerOrderItem['total']['discounts'][0]['amount']['currency']
382+
);
383+
$this->assertEquals(
384+
'null',
385+
$customerOrderItem['total']['discounts'][0]['label']
386+
);
387+
}
388+
205389
/**
206390
* @magentoApiDataFixture Magento/Customer/_files/customer.php
207391
* @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php
@@ -995,7 +1179,7 @@ private function addProductToCart(string $cartId, float $qty, string $sku): void
9951179
* @param int $selectionId
9961180
* @throws AuthenticationException
9971181
*/
998-
public function addBundleProductToCart(string $cartId, float $qty, string $sku, int $optionId1, int $selectionId1,int $optionId2, int $selectionId2)
1182+
public function addBundleProductToCart(string $cartId, float $qty, string $sku, int $optionId1, int $selectionId1, int $optionId2, int $selectionId2)
9991183
{
10001184
$query = <<<QUERY
10011185
mutation {
@@ -1034,7 +1218,6 @@ public function addBundleProductToCart(string $cartId, float $qty, string $sku,
10341218
$this->assertArrayHasKey('cart', $response['addBundleProductsToCart']);
10351219
}
10361220

1037-
10381221
/**
10391222
* @param string $cartId
10401223
* @param array $auth
@@ -1287,6 +1470,13 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
12871470
__typename
12881471
... on BundleOrderItem{
12891472
child_items{
1473+
discounts{
1474+
amount{
1475+
value
1476+
currency
1477+
}
1478+
label
1479+
}
12901480
__typename
12911481
product_sku
12921482
product_name
@@ -1304,13 +1494,27 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
13041494
total_tax{value}
13051495
subtotal { value currency }
13061496
taxes {amount{value currency} title rate}
1497+
discounts{
1498+
amount{
1499+
value
1500+
currency
1501+
}
1502+
label
1503+
}
13071504
total_shipping{value}
13081505
shipping_handling
13091506
{
13101507
amount_including_tax{value}
13111508
amount_excluding_tax{value}
13121509
total_amount{value}
13131510
taxes {amount{value} title rate}
1511+
discounts{
1512+
amount{
1513+
value
1514+
currency
1515+
}
1516+
label
1517+
}
13141518
}
13151519
}
13161520
}

0 commit comments

Comments
 (0)