10
10
use Magento \Bundle \Model \Selection ;
11
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
12
12
use Magento \Catalog \Model \Product ;
13
- use Magento \CatalogInventory \Api \Data \StockItemInterface ;
14
13
use Magento \Framework \Api \SearchCriteriaBuilder ;
15
14
use Magento \Framework \Exception \AuthenticationException ;
16
15
use Magento \GraphQl \GetCustomerAuthenticationHeader ;
17
16
use Magento \Sales \Api \OrderRepositoryInterface ;
18
- use Magento \Sales \Model \Order ;
19
17
use Magento \Sales \Model \ResourceModel \Order \Collection ;
20
18
use Magento \TestFramework \Helper \Bootstrap ;
21
19
use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -143,24 +141,10 @@ public function testGetCustomerOrderWithBundleProduct()
143
141
{
144
142
$ qty = 1 ;
145
143
$ bundleSku = 'bundle-product-two-dropdown-options ' ;
146
- /** @var Product $bundleProduct */
147
- $ bundleProduct = $ this ->productRepository ->get ($ bundleSku );
148
- /** @var $typeInstance \Magento\Bundle\Model\Product\Type */
149
- $ typeInstance = $ bundleProduct ->getTypeInstance ();
150
- /** @var $option \Magento\Bundle\Model\Option */
151
- $ option1 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getFirstItem ();
152
- $ option2 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getLastItem ();
153
- $ optionId1 =(int ) $ option1 ->getId ();
154
- $ optionId2 =(int ) $ option2 ->getId ();
155
- /** @var Selection $selection */
156
- $ selection1 = $ typeInstance ->getSelectionsCollection ([$ option1 ->getId ()], $ bundleProduct )->getFirstItem ();
157
- $ selectionId1 = (int )$ selection1 ->getSelectionId ();
158
-
159
- $ selection2 = $ typeInstance ->getSelectionsCollection ([$ option2 ->getId ()], $ bundleProduct )->getLastItem ();
160
- $ selectionId2 = (int )$ selection2 ->getSelectionId ();
144
+ $ optionsAndSelectionData = $ this ->getBundleOptionAndSelectionData ($ bundleSku );
161
145
162
146
$ cartId = $ this ->createEmptyCart ();
163
- $ this ->addBundleProductToCart ($ cartId , $ qty , $ bundleSku , $ optionId1 , $ selectionId1 , $ optionId2 , $ selectionId2 );
147
+ $ this ->addBundleProductQuery ($ cartId , $ qty , $ bundleSku , $ optionsAndSelectionData );
164
148
$ this ->setBillingAddress ($ cartId );
165
149
$ shippingMethod = $ this ->setShippingAddress ($ cartId );
166
150
$ paymentMethod = $ this ->setShippingMethod ($ cartId , $ shippingMethod );
@@ -221,23 +205,10 @@ public function testGetCustomerOrderWithBundleProductWithTaxesAndDiscounts()
221
205
{
222
206
$ qty = 4 ;
223
207
$ bundleSku = 'bundle-product-two-dropdown-options ' ;
224
- /** @var Product $bundleProduct */
225
- $ bundleProduct = $ this ->productRepository ->get ($ bundleSku );
226
- /** @var $typeInstance \Magento\Bundle\Model\Product\Type */
227
- $ typeInstance = $ bundleProduct ->getTypeInstance ();
228
- /** @var $option \Magento\Bundle\Model\Option */
229
- $ option1 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getFirstItem ();
230
- $ option2 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getLastItem ();
231
- $ optionId1 =(int ) $ option1 ->getId ();
232
- $ optionId2 =(int ) $ option2 ->getId ();
233
- /** @var Selection $selection */
234
- $ selection1 = $ typeInstance ->getSelectionsCollection ([$ option1 ->getId ()], $ bundleProduct )->getFirstItem ();
235
- $ selectionId1 = (int )$ selection1 ->getSelectionId ();
236
- $ selection2 = $ typeInstance ->getSelectionsCollection ([$ option2 ->getId ()], $ bundleProduct )->getLastItem ();
237
- $ selectionId2 = (int )$ selection2 ->getSelectionId ();
208
+ $ optionsAndSelectionData = $ this ->getBundleOptionAndSelectionData ($ bundleSku );
238
209
239
210
$ cartId = $ this ->createEmptyCart ();
240
- $ this ->addBundleProductToCart ($ cartId , $ qty , $ bundleSku , $ optionId1 , $ selectionId1 , $ optionId2 , $ selectionId2 );
211
+ $ this ->addBundleProductQuery ($ cartId , $ qty , $ bundleSku , $ optionsAndSelectionData );
241
212
$ this ->setBillingAddress ($ cartId );
242
213
$ shippingMethod = $ this ->setShippingAddress ($ cartId );
243
214
$ paymentMethod = $ this ->setShippingMethod ($ cartId , $ shippingMethod );
@@ -909,38 +880,28 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
909
880
20 ,
910
881
$ customerOrderItem ['total ' ]['total_shipping ' ]['value ' ]
911
882
);
912
- $ this ->assertEquals (
913
- 1.35 ,
914
- $ customerOrderItem ['total ' ]['taxes ' ][0 ]['amount ' ]['value ' ]
915
- );
916
- $ this ->assertEquals (
917
- 'USD ' ,
918
- $ customerOrderItem ['total ' ]['taxes ' ][0 ]['amount ' ]['currency ' ]
919
- );
920
- $ this ->assertEquals (
921
- 'US-TEST-*-Rate-1 ' ,
922
- $ customerOrderItem ['total ' ]['taxes ' ][0 ]['title ' ]
923
- );
924
- $ this ->assertEquals (
925
- 7.5 ,
926
- $ customerOrderItem ['total ' ]['taxes ' ][0 ]['rate ' ]
927
- );
928
- $ this ->assertEquals (
929
- 2.7 ,
930
- $ customerOrderItem ['total ' ]['taxes ' ][1 ]['amount ' ]['value ' ]
931
- );
932
- $ this ->assertEquals (
933
- 'USD ' ,
934
- $ customerOrderItem ['total ' ]['taxes ' ][1 ]['amount ' ]['currency ' ]
935
- );
936
- $ this ->assertEquals (
937
- 'US-TEST-*-Rate-1 ' ,
938
- $ customerOrderItem ['total ' ]['taxes ' ][1 ]['title ' ]
939
- );
940
- $ this ->assertEquals (
941
- 7.5 ,
942
- $ customerOrderItem ['total ' ]['taxes ' ][1 ]['rate ' ]
943
- );
883
+ $ this ->assertCount (2 , $ customerOrderItem ['total ' ]['taxes ' ]);
884
+ $ expectedProductAndShippingTaxes =
885
+ [
886
+ [
887
+ 'amount ' => [
888
+ 'value ' => 2.7 ,
889
+ 'currency ' => 'USD '
890
+ ],
891
+ 'title ' => 'US-TEST-*-Rate-1 ' ,
892
+ 'rate ' => 7.5
893
+ ],
894
+ [
895
+ 'amount ' => [
896
+ 'value ' => 1.35 ,
897
+ 'currency ' => 'USD '
898
+ ],
899
+
900
+ 'title ' => 'US-TEST-*-Rate-1 ' ,
901
+ 'rate ' => 7.5
902
+ ]
903
+ ];
904
+ $ this ->assertEquals ($ expectedProductAndShippingTaxes , $ customerOrderItem ['total ' ]['taxes ' ]);
944
905
$ this ->assertEquals (
945
906
21.5 ,
946
907
$ customerOrderItem ['total ' ]['shipping_handling ' ]['amount_including_tax ' ]['value ' ]
@@ -970,10 +931,7 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
970
931
2 ,
971
932
$ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['amount ' ]['value ' ]
972
933
);
973
- $ this ->assertEquals (
974
- 'USD ' ,
975
- $ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['amount ' ]['currency ' ]
976
- );
934
+
977
935
$ this ->assertEquals (
978
936
'null ' ,
979
937
$ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['label ' ]
@@ -982,10 +940,6 @@ private function assertTotalsWithTaxesAndDiscountsOnShippingAndTotal(array $cust
982
940
-6 ,
983
941
$ customerOrderItem ['total ' ]['discounts ' ][0 ]['amount ' ]['value ' ]
984
942
);
985
- $ this ->assertEquals (
986
- 'USD ' ,
987
- $ customerOrderItem ['total ' ]['discounts ' ][0 ]['amount ' ]['currency ' ]
988
- );
989
943
$ this ->assertEquals (
990
944
'null ' ,
991
945
$ customerOrderItem ['total ' ]['discounts ' ][0 ]['label ' ]
@@ -1027,7 +981,6 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
1027
981
32.25 ,
1028
982
$ customerOrderItem ['total ' ]['base_grand_total ' ]['value ' ]
1029
983
);
1030
-
1031
984
$ this ->assertEquals (
1032
985
32.25 ,
1033
986
$ customerOrderItem ['total ' ]['grand_total ' ]['value ' ]
@@ -1040,23 +993,31 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
1040
993
2.25 ,
1041
994
$ customerOrderItem ['total ' ]['total_tax ' ]['value ' ]
1042
995
);
1043
-
1044
996
$ this ->assertEquals (
1045
997
10 ,
1046
998
$ customerOrderItem ['total ' ]['total_shipping ' ]['value ' ]
1047
999
);
1048
- $ this ->assertEquals (
1049
- 0.75 ,
1050
- $ customerOrderItem ['total ' ]['taxes ' ][0 ]['amount ' ]['value ' ]
1051
- );
1052
- $ this ->assertEquals (
1053
- 'US-TEST-*-Rate-1 ' ,
1054
- $ customerOrderItem ['total ' ]['taxes ' ][0 ]['title ' ]
1055
- );
1056
- $ this ->assertEquals (
1057
- 7.5 ,
1058
- $ customerOrderItem ['total ' ]['taxes ' ][0 ]['rate ' ]
1059
- );
1000
+ $ expectedProductAndShippingTaxes =
1001
+ [
1002
+ [
1003
+ 'amount ' => [
1004
+ 'value ' => 1.5 ,
1005
+ 'currency ' => 'USD '
1006
+ ],
1007
+ 'title ' => 'US-TEST-*-Rate-1 ' ,
1008
+ 'rate ' => 7.5
1009
+ ],
1010
+ [
1011
+ 'amount ' => [
1012
+ 'value ' => 0.75 ,
1013
+ 'currency ' => 'USD '
1014
+ ],
1015
+
1016
+ 'title ' => 'US-TEST-*-Rate-1 ' ,
1017
+ 'rate ' => 7.5
1018
+ ]
1019
+ ];
1020
+ $ this ->assertEquals ($ expectedProductAndShippingTaxes , $ customerOrderItem ['total ' ]['taxes ' ]);
1060
1021
$ this ->assertEquals (
1061
1022
10.75 ,
1062
1023
$ customerOrderItem ['total ' ]['shipping_handling ' ]['amount_including_tax ' ]['value ' ]
@@ -1072,7 +1033,7 @@ private function assertTotalsAndShippingWithExcludedTaxSetting(array $customerOr
1072
1033
1073
1034
$ this ->assertEquals (
1074
1035
0.75 ,
1075
- $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][0 ]['amount ' ]['value ' ]
1036
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][1 ]['amount ' ]['value ' ]
1076
1037
);
1077
1038
$ this ->assertEquals (
1078
1039
'US-TEST-*-Rate-1 ' ,
@@ -1157,15 +1118,7 @@ private function addProductToCart(string $cartId, float $qty, string $sku): void
1157
1118
$ this ->graphQlMutation ($ query , [], '' , $ this ->customerAuthenticationHeader ->execute ($ currentEmail , $ currentPassword ));
1158
1119
}
1159
1120
1160
- /**
1161
- * @param string $cartId
1162
- * @param float $qty
1163
- * @param string $sku
1164
- * @param int $optionId
1165
- * @param int $selectionId
1166
- * @throws AuthenticationException
1167
- */
1168
- public function addBundleProductToCart (string $ cartId , float $ qty , string $ sku , int $ optionId1 , int $ selectionId1 , int $ optionId2 , int $ selectionId2 )
1121
+ public function addBundleProductQuery (string $ cartId , float $ qty , string $ sku , array $ optionsAndSelectionData )
1169
1122
{
1170
1123
$ query = <<<QUERY
1171
1124
mutation {
@@ -1179,14 +1132,14 @@ public function addBundleProductToCart(string $cartId, float $qty, string $sku,
1179
1132
}
1180
1133
bundle_options:[
1181
1134
{
1182
- id: $ optionId1
1135
+ id: $ optionsAndSelectionData [ 0 ]
1183
1136
quantity:1
1184
- value:[" {$ selectionId1 }"]
1137
+ value:[" {$ optionsAndSelectionData [ 1 ] }"]
1185
1138
}
1186
1139
{
1187
- id: $ optionId2
1140
+ id: $ optionsAndSelectionData [ 2 ]
1188
1141
quantity:2
1189
- value:[" {$ selectionId2 }"]
1142
+ value:[" {$ optionsAndSelectionData [ 3 ] }"]
1190
1143
}
1191
1144
]
1192
1145
}
@@ -1203,7 +1156,6 @@ public function addBundleProductToCart(string $cartId, float $qty, string $sku,
1203
1156
$ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->customerAuthenticationHeader ->execute ($ currentEmail , $ currentPassword ));
1204
1157
$ this ->assertArrayHasKey ('cart ' , $ response ['addBundleProductsToCart ' ]);
1205
1158
}
1206
-
1207
1159
/**
1208
1160
* @param string $cartId
1209
1161
* @param array $auth
@@ -1641,4 +1593,30 @@ private function assertTotals(array $response, int $expectedCount): void
1641
1593
);
1642
1594
}
1643
1595
}
1596
+
1597
+ /**
1598
+ * @param string $bundleSku
1599
+ * @return array
1600
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
1601
+ */
1602
+ private function getBundleOptionAndSelectionData ($ bundleSku ): array
1603
+ {
1604
+ /** @var Product $bundleProduct */
1605
+ $ bundleProduct = $ this ->productRepository ->get ($ bundleSku );
1606
+ /** @var $typeInstance \Magento\Bundle\Model\Product\Type */
1607
+ $ typeInstance = $ bundleProduct ->getTypeInstance ();
1608
+ $ optionsAndSelections = [];
1609
+ /** @var $option \Magento\Bundle\Model\Option */
1610
+ $ option1 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getFirstItem ();
1611
+ $ option2 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getLastItem ();
1612
+ $ optionId1 =(int ) $ option1 ->getId ();
1613
+ $ optionId2 =(int ) $ option2 ->getId ();
1614
+ /** @var Selection $selection */
1615
+ $ selection1 = $ typeInstance ->getSelectionsCollection ([$ option1 ->getId ()], $ bundleProduct )->getFirstItem ();
1616
+ $ selectionId1 = (int )$ selection1 ->getSelectionId ();
1617
+ $ selection2 = $ typeInstance ->getSelectionsCollection ([$ option2 ->getId ()], $ bundleProduct )->getLastItem ();
1618
+ $ selectionId2 = (int )$ selection2 ->getSelectionId ();
1619
+ array_push ($ optionsAndSelections , $ optionId1 , $ selectionId1 , $ optionId2 , $ selectionId2 );
1620
+ return $ optionsAndSelections ;
1621
+ }
1644
1622
}
0 commit comments