14
14
use Magento \Framework \Api \SearchCriteriaBuilder ;
15
15
use Magento \Framework \Exception \AuthenticationException ;
16
16
use Magento \GraphQl \GetCustomerAuthenticationHeader ;
17
- use Magento \Integration \Api \CustomerTokenServiceInterface ;
18
17
use Magento \Sales \Api \OrderRepositoryInterface ;
19
18
use Magento \Sales \Model \Order ;
20
19
use Magento \Sales \Model \ResourceModel \Order \Collection ;
26
25
*/
27
26
class RetrieveOrdersByOrderNumberTest extends GraphQlAbstract
28
27
{
29
- /**
30
- * @var CustomerTokenServiceInterface
31
- */
32
- private $ customerTokenService ;
33
-
34
28
/** @var OrderRepositoryInterface */
35
29
private $ orderRepository ;
36
30
37
31
/** @var SearchCriteriaBuilder */
38
32
private $ searchCriteriaBuilder ;
39
33
40
- /** @var Order\Item */
41
- private $ orderItem ;
42
-
43
34
/** @var GetCustomerAuthenticationHeader */
44
35
private $ customerAuthenticationHeader ;
45
36
@@ -50,12 +41,10 @@ protected function setUp():void
50
41
{
51
42
parent ::setUp ();
52
43
$ objectManager = Bootstrap::getObjectManager ();
53
- $ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
54
44
$ this ->customerAuthenticationHeader = $ objectManager ->get (GetCustomerAuthenticationHeader::class);
55
45
$ this ->orderRepository = $ objectManager ->get (OrderRepositoryInterface::class);
56
46
$ this ->searchCriteriaBuilder = $ objectManager ->get (SearchCriteriaBuilder::class);
57
47
$ this ->productRepository = $ objectManager ->get (ProductRepositoryInterface::class);
58
- $ this ->orderItem = $ objectManager ->get (Order \Item::class);
59
48
}
60
49
61
50
/**
@@ -112,17 +101,16 @@ public function testGetCustomerOrdersSimpleProductQuery()
112
101
$ this ->assertArrayHasKey ('items ' , $ response ['customer ' ]['orders ' ]);
113
102
$ this ->assertNotEmpty ($ response ['customer ' ]['orders ' ]['items ' ]);
114
103
$ customerOrderItemsInResponse = $ response ['customer ' ]['orders ' ]['items ' ][0 ];
115
- $ expectedCount = count ($ response ['customer ' ]['orders ' ]['items ' ]);
116
104
$ this ->assertArrayHasKey ('items ' , $ customerOrderItemsInResponse );
117
105
$ this ->assertNotEmpty ($ customerOrderItemsInResponse ['items ' ]);
118
106
119
107
$ searchCriteria = $ this ->searchCriteriaBuilder ->addFilter ('increment_id ' , '100000002 ' )
120
108
->create ();
121
109
/** @var \Magento\Sales\Api\Data\OrderInterface[] $items */
122
- $ items = $ this ->orderRepository ->getList ($ searchCriteria )->getItems ();
123
- foreach ($ items as $ item ) {
124
- $ orderId = $ item ->getEntityId ();
125
- $ orderNumber = $ item ->getIncrementId ();
110
+ $ orders = $ this ->orderRepository ->getList ($ searchCriteria )->getItems ();
111
+ foreach ($ orders as $ order ) {
112
+ $ orderId = $ order ->getEntityId ();
113
+ $ orderNumber = $ order ->getIncrementId ();
126
114
$ this ->assertEquals ($ orderId , $ customerOrderItemsInResponse ['id ' ]);
127
115
$ this ->assertEquals ($ orderNumber , $ customerOrderItemsInResponse ['number ' ]);
128
116
$ this ->assertEquals ('Processing ' , $ customerOrderItemsInResponse ['status ' ]);
@@ -155,16 +143,6 @@ public function testGetCustomerOrderWithBundleProduct()
155
143
{
156
144
$ qty = 1 ;
157
145
$ bundleSku = 'bundle-product-two-dropdown-options ' ;
158
- $ simpleProductSku = 'simple2 ' ;
159
- /** @var Product $simple */
160
- $ simple = $ this ->productRepository ->get ($ simpleProductSku );
161
- $ stockData =[
162
- StockItemInterface::QTY => 200 ,
163
- StockItemInterface::MANAGE_STOCK =>true ,
164
- StockItemInterface::IS_IN_STOCK =>true
165
- ];
166
- $ simple ->setQuantityAndStockStatus ($ stockData );
167
- $ this ->productRepository ->save ($ simple );
168
146
/** @var Product $bundleProduct */
169
147
$ bundleProduct = $ this ->productRepository ->get ($ bundleSku );
170
148
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
@@ -192,13 +170,40 @@ public function testGetCustomerOrderWithBundleProduct()
192
170
193
171
$ customerOrderItems = $ customerOrderResponse [0 ];
194
172
$ this ->assertEquals ("Pending " , $ customerOrderItems ['status ' ]);
195
-
196
173
$ bundledItemInTheOrder = $ customerOrderItems ['items ' ][0 ];
197
174
$ 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 ' ]);
175
+ $ priceOfBundledItemInOrder = $ bundledItemInTheOrder ['product_sale_price ' ]['value ' ];
176
+ $ this ->assertEquals (15 , $ priceOfBundledItemInOrder );
177
+ $ this ->assertArrayHasKey ('bundle_options ' , $ bundledItemInTheOrder );
178
+ $ bundleOptionsFromResponse = $ bundledItemInTheOrder ['bundle_options ' ];
179
+ $ this ->assertNotEmpty ($ bundleOptionsFromResponse );
180
+ $ this ->assertEquals (2 , count ($ bundleOptionsFromResponse ));
181
+ $ expectedBundleOptions =
182
+ [
183
+ [ '__typename ' => 'SelectedBundleOptionItems ' ,
184
+ 'label ' => 'Drop Down Option 1 ' ,
185
+ 'items ' => [
186
+ [
187
+ 'product_sku ' => 'simple1 ' ,
188
+ 'product_name ' => 'Simple Product1 ' ,
189
+ 'product_type ' => 'simple ' ,
190
+ 'quantity_ordered ' => 1
191
+ ]
192
+ ]
193
+ ],
194
+ [ '__typename ' => 'SelectedBundleOptionItems ' ,
195
+ 'label ' => 'Drop Down Option 2 ' ,
196
+ 'items ' => [
197
+ [
198
+ 'product_sku ' => 'simple2 ' ,
199
+ 'product_name ' => 'Simple Product2 ' ,
200
+ 'product_type ' => 'simple ' ,
201
+ 'quantity_ordered ' => 2
202
+ ]
203
+ ]
204
+ ],
205
+ ];
206
+ $ this ->assertEquals ($ expectedBundleOptions , $ bundleOptionsFromResponse );
202
207
$ this ->deleteOrder ();
203
208
}
204
209
@@ -481,12 +486,13 @@ public function testGetMatchingOrdersForLowerQueryLength()
481
486
*/
482
487
public function testGetMultipleCustomerOrdersQueryWithDefaultPagination ()
483
488
{
489
+ $ orderNumbers = ['100000007 ' , '100000008 ' ];
484
490
$ query =
485
491
<<<QUERY
486
492
{
487
493
customer
488
494
{
489
- orders(filter:{number:{in:["100000007 ","100000008 "]}}){
495
+ orders(filter:{number:{in:[" { $ orderNumbers [ 0 ]} "," { $ orderNumbers [ 1 ]} "]}}){
490
496
total_count
491
497
page_info{
492
498
total_pages
@@ -545,15 +551,14 @@ public function testGetMultipleCustomerOrdersQueryWithDefaultPagination()
545
551
$ customerOrderItemsInResponse = $ response ['customer ' ]['orders ' ]['items ' ];
546
552
$ this ->assertCount (2 , $ response ['customer ' ]['orders ' ]['items ' ]);
547
553
548
- $ orderNumbers = ['100000007 ' , '100000008 ' ];
549
554
$ searchCriteria = $ this ->searchCriteriaBuilder ->addFilter ('increment_id ' , $ orderNumbers , 'in ' )
550
555
->create ();
551
556
/** @var \Magento\Sales\Api\Data\OrderInterface[] $items */
552
- $ items = $ this ->orderRepository ->getList ($ searchCriteria )->getItems ();
557
+ $ orders = $ this ->orderRepository ->getList ($ searchCriteria )->getItems ();
553
558
$ key = 0 ;
554
- foreach ($ items as $ item ) {
555
- $ orderId = $ item ->getEntityId ();
556
- $ orderNumber = $ item ->getIncrementId ();
559
+ foreach ($ orders as $ order ) {
560
+ $ orderId = $ order ->getEntityId ();
561
+ $ orderNumber = $ order ->getIncrementId ();
557
562
$ this ->assertEquals ($ orderId , $ customerOrderItemsInResponse [$ key ]['id ' ]);
558
563
$ this ->assertEquals ($ orderNumber , $ customerOrderItemsInResponse [$ key ]['number ' ]);
559
564
$ this ->assertEquals ('Processing ' , $ customerOrderItemsInResponse [$ key ]['status ' ]);
@@ -1461,30 +1466,23 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
1461
1466
orders(filter:{number:{eq:" {$ orderNumber }"}}) {
1462
1467
total_count
1463
1468
items {
1469
+ id
1464
1470
number
1465
1471
order_date
1466
1472
status
1467
1473
items{
1474
+ __typename
1468
1475
product_sku
1476
+ product_name
1477
+ product_url_key
1478
+ product_sale_price{value}
1469
1479
quantity_ordered
1470
1480
__typename
1471
1481
... on BundleOrderItem{
1472
- child_items{
1473
- discounts{
1474
- amount{
1475
- value
1476
- currency
1477
- }
1478
- label
1479
- }
1482
+ bundle_options{
1480
1483
__typename
1481
- product_sku
1482
- product_name
1483
- product_sku
1484
- product_url_key
1485
- product_sale_price{value}
1486
- product_sale_price{value currency}
1487
- quantity_ordered
1484
+ label
1485
+ items{ product_sku product_name product_type quantity_ordered}
1488
1486
}
1489
1487
}
1490
1488
}
@@ -1494,28 +1492,15 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
1494
1492
total_tax{value}
1495
1493
subtotal { value currency }
1496
1494
taxes {amount{value currency} title rate}
1497
- discounts{
1498
- amount{
1499
- value
1500
- currency
1501
- }
1502
- label
1503
- }
1504
1495
total_shipping{value}
1505
1496
shipping_handling
1506
1497
{
1507
1498
amount_including_tax{value}
1508
1499
amount_excluding_tax{value}
1509
1500
total_amount{value}
1510
1501
taxes {amount{value} title rate}
1511
- discounts{
1512
- amount{
1513
- value
1514
- currency
1515
- }
1516
- label
1517
- }
1518
1502
}
1503
+ discounts {amount{value currency} label}
1519
1504
}
1520
1505
}
1521
1506
}
0 commit comments