@@ -122,6 +122,7 @@ public function testCreditMemoForLoggedInCustomerQuery(): void
122
122
'total_shipping ' => [
123
123
'value ' => 0
124
124
],
125
+ 'total_tax ' => [],
125
126
'shipping_handling ' => [
126
127
'amount_including_tax ' => [
127
128
'value ' => 0
@@ -167,6 +168,7 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
167
168
$ this ->setPaymentMethod ($ cartId , $ paymentMethod );
168
169
$ orderNumber = $ this ->placeOrder ($ cartId );
169
170
$ this ->prepareInvoice ($ orderNumber , 2 );
171
+ // Create a credit memo
170
172
$ order = $ this ->order ->loadByIncrementId ($ orderNumber );
171
173
/** @var Order\Item $orderItem */
172
174
$ orderItem = current ($ order ->getAllItems ());
@@ -188,7 +190,6 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
188
190
189
191
$ this ->creditMemoService ->refund ($ creditMemo , true );
190
192
$ response = $ this ->getCustomerOrderWithCreditMemoQuery ();
191
- $ i = 0 ;
192
193
$ expectedCreditMemoData = [
193
194
[
194
195
'comments ' => [
@@ -218,6 +219,7 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
218
219
'total_shipping ' => [
219
220
'value ' => 10
220
221
],
222
+ 'total_tax ' => [],
221
223
'shipping_handling ' => [
222
224
'amount_including_tax ' => [
223
225
'value ' => 10
@@ -251,6 +253,129 @@ public function testCreditMemoForBundledProductsWithPartialRefund()
251
253
}
252
254
}
253
255
256
+ /**
257
+ * Test customer order with credit memo details for bundle products with taxes and discounts
258
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
259
+ * @magentoApiDataFixture Magento/Bundle/_files/bundle_product_two_dropdown_options.php
260
+ * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
261
+ * @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
262
+ * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
263
+ */
264
+ public function testCreditMemoForBundleProductWithTaxesAndDiscounts ()
265
+ {
266
+ $ quantity = 2 ;
267
+ $ bundleSku = 'bundle-product-two-dropdown-options ' ;
268
+ $ optionsAndSelectionData = $ this ->getBundleOptionAndSelectionData ($ bundleSku );
269
+
270
+ $ cartId = $ this ->createEmptyCart ();
271
+ $ this ->addBundleProductQuery ($ cartId , $ quantity , $ bundleSku , $ optionsAndSelectionData );
272
+ $ this ->setBillingAddress ($ cartId );
273
+ $ shippingMethod = $ this ->setShippingAddress ($ cartId );
274
+ $ paymentMethod = $ this ->setShippingMethod ($ cartId , $ shippingMethod );
275
+ $ this ->setPaymentMethod ($ cartId , $ paymentMethod );
276
+ $ orderNumber = $ this ->placeOrder ($ cartId );
277
+ $ this ->prepareInvoice ($ orderNumber , 2 );
278
+
279
+ $ order = $ this ->order ->loadByIncrementId ($ orderNumber );
280
+ /** @var Order\Item $orderItem */
281
+ $ orderItem = current ($ order ->getAllItems ());
282
+ $ orderItem ->setQtyRefunded (1 );
283
+ $ order ->addItem ($ orderItem );
284
+ $ order ->save ();
285
+
286
+ $ creditMemo = $ this ->creditMemoFactory ->createByOrder ($ order , $ order ->getData ());
287
+ $ creditMemo ->setOrder ($ order );
288
+ $ creditMemo ->setState (1 );
289
+ $ creditMemo ->setSubtotal (15 );
290
+ $ creditMemo ->setBaseSubTotal (15 );
291
+ $ creditMemo ->setShippingAmount (10 );
292
+ $ creditMemo ->setTaxAmount (1.69 );
293
+ $ creditMemo ->setBaseGrandTotal (24.19 );
294
+ $ creditMemo ->setGrandTotal (24.19 );
295
+ $ creditMemo ->setAdjustment (0.00 );
296
+ $ creditMemo ->setDiscountAmount (-2.5 );
297
+ $ creditMemo ->setDiscountDescription ('Discount Label for 10% off ' );
298
+ $ creditMemo ->addComment ("Test comment for refund with taxes and discount " , false , true );
299
+ $ creditMemo ->save ();
300
+
301
+ $ this ->creditMemoService ->refund ($ creditMemo , true );
302
+ //$this->prepareCreditmemoAndRefund($orderNumber);
303
+ $ response = $ this ->getCustomerOrderWithCreditMemoQuery ();
304
+ $ expectedCreditMemoData = [
305
+ [
306
+ 'comments ' => [
307
+ ['message ' => 'Test comment for refund with taxes and discount ' ]
308
+ ],
309
+ 'items ' => [
310
+ [
311
+ 'product_name ' => 'Bundle Product With Two dropdown options ' ,
312
+ 'product_sku ' => 'bundle-product-two-dropdown-options-simple1-simple2 ' ,
313
+ 'product_sale_price ' => [
314
+ 'value ' => 15
315
+ ],
316
+ 'quantity_refunded ' => 1
317
+ ],
318
+
319
+ ],
320
+ 'total ' => [
321
+ 'subtotal ' => [
322
+ 'value ' => 15
323
+ ],
324
+ 'grand_total ' => [
325
+ 'value ' => 24.19
326
+ ],
327
+ 'base_grand_total ' => [
328
+ 'value ' => 24.19
329
+ ],
330
+ 'total_shipping ' => [
331
+ 'value ' => 10
332
+ ],
333
+ 'total_tax ' => [
334
+ 'value ' => 1.69
335
+ ],
336
+ 'shipping_handling ' => [
337
+ 'amount_including_tax ' => [
338
+ 'value ' => 10.75
339
+ ],
340
+ 'amount_excluding_tax ' => [
341
+ 'value ' => 10
342
+ ],
343
+ 'total_amount ' => [
344
+ 'value ' => 10
345
+ ],
346
+ 'taxes ' => [
347
+ 0 => [
348
+ 'amount ' =>['value ' => 1.69 ],
349
+ 'title ' => 'US-TEST-*-Rate-1 ' ,
350
+ 'rate ' => 7.5
351
+ ]
352
+ ],
353
+ 'discounts ' => [
354
+ 0 => ['amount ' =>['value ' => 2.5 ],
355
+ 'label ' => 'Discount Label for 10% off '
356
+ ]
357
+ ],
358
+ ],
359
+ 'adjustment ' => [
360
+ 'value ' => 0
361
+ ]
362
+ ]
363
+ ]
364
+ ];
365
+ $ firstOrderItem = current ($ response ['customer ' ]['orders ' ]['items ' ] ?? []);
366
+
367
+ $ creditMemos = $ firstOrderItem ['credit_memos ' ] ?? [];
368
+ $ this ->assertResponseFields ($ creditMemos , $ expectedCreditMemoData );
369
+ $ this ->deleteOrder ();
370
+ $ searchCriteria = $ this ->searchCriteriaBuilder ->addFilter ('increment_id ' , $ orderNumber )
371
+ ->create ();
372
+ $ creditmemoRepository = Bootstrap::getObjectManager ()->get (CreditmemoRepositoryInterface::class);
373
+ $ creditmemos = $ creditmemoRepository ->getList ($ searchCriteria )->getItems ();
374
+ foreach ($ creditmemos as $ creditmemo ) {
375
+ $ creditmemoRepository ->delete ($ creditmemo );
376
+ }
377
+ }
378
+
254
379
/**
255
380
* @return string
256
381
*/
@@ -633,6 +758,9 @@ private function getCustomerOrderWithCreditMemoQuery(): array
633
758
total_shipping {
634
759
value
635
760
}
761
+ total_tax {
762
+ value
763
+ }
636
764
shipping_handling {
637
765
amount_including_tax{value}
638
766
amount_excluding_tax{value}
0 commit comments