@@ -169,19 +169,12 @@ public function testCustomerOrdersSimpleProductWithTaxesAndDiscounts()
169169 private function assertTotalsWithTaxesAndDiscounts (array $ customerOrderItemTotal ): void
170170 {
171171 $ this ->assertCount (1 , $ customerOrderItemTotal ['taxes ' ]);
172- $ expectedProductAndShippingTaxes = [4.05 ];
173- $ totalTaxes = [];
174- foreach ($ customerOrderItemTotal ['taxes ' ] as $ totalTaxFromResponse ) {
175- array_push ($ totalTaxes , $ totalTaxFromResponse ['amount ' ]['value ' ]);
176- }
177- foreach ($ totalTaxes as $ value ) {
178- $ this ->assertTrue (in_array ($ value , $ expectedProductAndShippingTaxes ));
179- }
180- foreach ($ customerOrderItemTotal ['taxes ' ] as $ taxData ) {
181- $ this ->assertEquals ('USD ' , $ taxData ['amount ' ]['currency ' ]);
182- $ this ->assertEquals ('US-TEST-*-Rate-1 ' , $ taxData ['title ' ]);
183- $ this ->assertEquals (7.5 , $ taxData ['rate ' ]);
184- }
172+ $ taxData = $ customerOrderItemTotal ['taxes ' ][0 ];
173+ $ this ->assertEquals ('USD ' , $ taxData ['amount ' ]['currency ' ]);
174+ $ this ->assertEquals (4.05 , $ taxData ['amount ' ]['value ' ]);
175+ $ this ->assertEquals ('US-TEST-*-Rate-1 ' , $ taxData ['title ' ]);
176+ $ this ->assertEquals (7.5 , $ taxData ['rate ' ]);
177+
185178 unset($ customerOrderItemTotal ['taxes ' ]);
186179 $ assertionMap = [
187180 'base_grand_total ' => ['value ' => 58.05 , 'currency ' =>'USD ' ],
@@ -215,6 +208,93 @@ private function assertTotalsWithTaxesAndDiscounts(array $customerOrderItemTotal
215208 $ this ->assertResponseFields ($ customerOrderItemTotal , $ assertionMap );
216209 }
217210
211+ /**
212+ * Verify the customer order with tax, discount with shipping tax class set for calculation setting
213+ *
214+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
215+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
216+ * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
217+ * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_al.php
218+ * @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
219+ * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
220+ */
221+ public function testCustomerOrdersSimpleProductWithTaxesAndDiscountsWithTwoRules ()
222+ {
223+ $ quantity = 4 ;
224+ $ sku = 'simple1 ' ;
225+ $ cartId = $ this ->createEmptyCart ();
226+ $ this ->addProductToCart ($ cartId , $ quantity , $ sku );
227+ $ this ->setBillingAddress ($ cartId );
228+ $ shippingMethod = $ this ->setShippingAddress ($ cartId );
229+ $ paymentMethod = $ this ->setShippingMethod ($ cartId , $ shippingMethod );
230+ $ this ->setPaymentMethod ($ cartId , $ paymentMethod );
231+ $ orderNumber = $ this ->placeOrder ($ cartId );
232+ $ customerOrderResponse = $ this ->getCustomerOrderQuery ($ orderNumber );
233+ // Asserting discounts on order item level
234+ $ this ->assertEquals (4 , $ customerOrderResponse [0 ]['items ' ][0 ]['discounts ' ][0 ]['amount ' ]['value ' ]);
235+ $ this ->assertEquals ('USD ' , $ customerOrderResponse [0 ]['items ' ][0 ]['discounts ' ][0 ]['amount ' ]['currency ' ]);
236+ $ this ->assertEquals ('Discount ' , $ customerOrderResponse [0 ]['items ' ][0 ]['discounts ' ][0 ]['label ' ]);
237+ $ customerOrderItem = $ customerOrderResponse [0 ];
238+ $ this ->assertTotalsWithTaxesAndDiscountsWithTwoRules ($ customerOrderItem ['total ' ]);
239+ $ this ->deleteOrder ();
240+ }
241+
242+ /**
243+ * @param array $customerOrderItemTotal
244+ */
245+ private function assertTotalsWithTaxesAndDiscountsWithTwoRules (array $ customerOrderItemTotal ): void
246+ {
247+ $ this ->assertCount (2 , $ customerOrderItemTotal ['taxes ' ]);
248+ $ taxData = $ customerOrderItemTotal ['taxes ' ][0 ];
249+ $ this ->assertEquals ('USD ' , $ taxData ['amount ' ]['currency ' ]);
250+ $ this ->assertEquals (4.05 , $ taxData ['amount ' ]['value ' ]);
251+ $ this ->assertEquals ('US-TEST-*-Rate-1 ' , $ taxData ['title ' ]);
252+ $ this ->assertEquals (7.5 , $ taxData ['rate ' ]);
253+
254+ $ secondTaxData = $ customerOrderItemTotal ['taxes ' ][1 ];
255+ $ this ->assertEquals ('USD ' , $ secondTaxData ['amount ' ]['currency ' ]);
256+ $ this ->assertEquals (2.97 , $ secondTaxData ['amount ' ]['value ' ]);
257+ $ this ->assertEquals ('US-AL-*-Rate-1 ' , $ secondTaxData ['title ' ]);
258+ $ this ->assertEquals (5.5 , $ secondTaxData ['rate ' ]);
259+
260+ unset($ customerOrderItemTotal ['taxes ' ]);
261+ $ assertionMap = [
262+ 'base_grand_total ' => ['value ' => 61.02 , 'currency ' =>'USD ' ],
263+ 'grand_total ' => ['value ' => 61.02 , 'currency ' =>'USD ' ],
264+ 'subtotal ' => ['value ' => 40 , 'currency ' =>'USD ' ],
265+ 'total_tax ' => ['value ' => 7.02 , 'currency ' =>'USD ' ],
266+ 'total_shipping ' => ['value ' => 20 , 'currency ' =>'USD ' ],
267+ 'shipping_handling ' => [
268+ 'amount_including_tax ' => ['value ' => 22.6 ],
269+ 'amount_excluding_tax ' => ['value ' => 20 ],
270+ 'total_amount ' => ['value ' => 20 , 'currency ' =>'USD ' ],
271+ 'discounts ' => [
272+ 0 => ['amount ' =>['value ' => 2 , 'currency ' =>'USD ' ],
273+ 'label ' => 'Discount '
274+ ]
275+ ],
276+ 'taxes ' => [
277+ 0 => [
278+ 'amount ' =>['value ' => 1.35 ],
279+ 'title ' => 'US-TEST-*-Rate-1 ' ,
280+ 'rate ' => 7.5
281+ ],
282+ 1 => [
283+ 'amount ' =>['value ' => 0.99 ],
284+ 'title ' => 'US-AL-*-Rate-1 ' ,
285+ 'rate ' => 5.5
286+ ]
287+ ]
288+ ],
289+ 'discounts ' => [
290+ 0 => ['amount ' => [ 'value ' => -6 , 'currency ' =>'USD ' ],
291+ 'label ' => 'Discount '
292+ ]
293+ ]
294+ ];
295+ $ this ->assertResponseFields ($ customerOrderItemTotal , $ assertionMap );
296+ }
297+
218298 /**
219299 * @magentoApiDataFixture Magento/Customer/_files/customer.php
220300 * @magentoApiDataFixture Magento/GraphQl/Sales/_files/orders_with_customer.php
@@ -745,20 +825,12 @@ public function testCustomerOrderWithTaxesExcludedOnShipping()
745825 private function assertTotalsAndShippingWithExcludedTaxSetting ($ customerOrderItemTotal ): void
746826 {
747827 $ this ->assertCount (1 , $ customerOrderItemTotal ['taxes ' ]);
748- $ expectedProductAndShippingTaxes = [2.25 ];
828+ $ taxData = $ customerOrderItemTotal ['taxes ' ][0 ];
829+ $ this ->assertEquals ('USD ' , $ taxData ['amount ' ]['currency ' ]);
830+ $ this ->assertEquals (2.25 , $ taxData ['amount ' ]['value ' ]);
831+ $ this ->assertEquals ('US-TEST-*-Rate-1 ' , $ taxData ['title ' ]);
832+ $ this ->assertEquals (7.5 , $ taxData ['rate ' ]);
749833
750- $ totalTaxes = [];
751- foreach ($ customerOrderItemTotal ['taxes ' ] as $ totalTaxFromResponse ) {
752- array_push ($ totalTaxes , $ totalTaxFromResponse ['amount ' ]['value ' ]);
753- }
754- foreach ($ totalTaxes as $ value ) {
755- $ this ->assertTrue (in_array ($ value , $ expectedProductAndShippingTaxes ));
756- }
757- foreach ($ customerOrderItemTotal ['taxes ' ] as $ taxData ) {
758- $ this ->assertEquals ('USD ' , $ taxData ['amount ' ]['currency ' ]);
759- $ this ->assertEquals ('US-TEST-*-Rate-1 ' , $ taxData ['title ' ]);
760- $ this ->assertEquals (7.5 , $ taxData ['rate ' ]);
761- }
762834 unset($ customerOrderItemTotal ['taxes ' ]);
763835 $ assertionMap = [
764836 'base_grand_total ' => ['value ' => 32.25 , 'currency ' =>'USD ' ],
@@ -820,19 +892,13 @@ public function testCustomerOrderWithTaxesIncludedOnShippingAndTotals()
820892 private function assertTotalsAndShippingWithTaxes (array $ customerOrderItemTotal ): void
821893 {
822894 $ this ->assertCount (1 , $ customerOrderItemTotal ['taxes ' ]);
823- $ expectedProductAndShippingTaxes = [2.25 ];
824- $ totalTaxes = [];
825- foreach ($ customerOrderItemTotal ['taxes ' ] as $ totalTaxFromResponse ) {
826- array_push ($ totalTaxes , $ totalTaxFromResponse ['amount ' ]['value ' ]);
827- }
828- foreach ($ totalTaxes as $ value ) {
829- $ this ->assertTrue (in_array ($ value , $ expectedProductAndShippingTaxes ));
830- }
831- foreach ($ customerOrderItemTotal ['taxes ' ] as $ taxData ) {
832- $ this ->assertEquals ('USD ' , $ taxData ['amount ' ]['currency ' ]);
833- $ this ->assertEquals ('US-TEST-*-Rate-1 ' , $ taxData ['title ' ]);
834- $ this ->assertEquals (7.5 , $ taxData ['rate ' ]);
835- }
895+
896+ $ taxData = $ customerOrderItemTotal ['taxes ' ][0 ];
897+ $ this ->assertEquals ('USD ' , $ taxData ['amount ' ]['currency ' ]);
898+ $ this ->assertEquals (2.25 , $ taxData ['amount ' ]['value ' ]);
899+ $ this ->assertEquals ('US-TEST-*-Rate-1 ' , $ taxData ['title ' ]);
900+ $ this ->assertEquals (7.5 , $ taxData ['rate ' ]);
901+
836902 unset($ customerOrderItemTotal ['taxes ' ]);
837903 unset($ customerOrderItemTotal ['shipping_handling ' ]['discounts ' ]);
838904 $ assertionMap = [
0 commit comments