@@ -871,6 +871,89 @@ public function testSetNewBillingAddressWithSaveInAddressBook()
871
871
}
872
872
}
873
873
874
+ /**
875
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
876
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
877
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
878
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
879
+ */
880
+ public function testSetBillingAddressAndPlaceOrder ()
881
+ {
882
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
883
+ $ query = <<<QUERY
884
+ mutation {
885
+ setBillingAddressOnCart(
886
+ input: {
887
+ cart_id: " $ maskedQuoteId"
888
+ billing_address: {
889
+ same_as_shipping: true
890
+ address: {
891
+ firstname: "test firstname"
892
+ lastname: "test lastname"
893
+ company: "test company"
894
+ street: ["test street 1", "test street 2"]
895
+ city: "test city"
896
+ region: "AZ"
897
+ postcode: "887766"
898
+ country_code: "US"
899
+ telephone: "88776655"
900
+ save_in_address_book: true
901
+ }
902
+ }
903
+ }
904
+ ) {
905
+ cart {
906
+ billing_address {
907
+ firstname
908
+ lastname
909
+ company
910
+ street
911
+ city
912
+ postcode
913
+ telephone
914
+ country {
915
+ code
916
+ label
917
+ }
918
+ __typename
919
+ }
920
+ }
921
+ }
922
+ }
923
+ QUERY ;
924
+ $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
925
+ $ this ->graphQlMutation (
926
+ $ this ->getSetShippingMethodsQuery ($ maskedQuoteId , 'flatrate ' , 'flatrate ' ),
927
+ [],
928
+ '' ,
929
+ $ this ->getHeaderMap ()
930
+ );
931
+ $ this ->graphQlMutation (
932
+ $ this ->getSetPaymentMethodQuery (
933
+ $ maskedQuoteId ,
934
+ 'checkmo '
935
+ ),
936
+ [],
937
+ '' ,
938
+ $ this ->getHeaderMap ()
939
+ );
940
+ $ this ->graphQlMutation (
941
+ $ this ->getPlaceOrderQuery ($ maskedQuoteId ),
942
+ [],
943
+ '' ,
944
+ $ this ->getHeaderMap ()
945
+ );
946
+ $ customer = $ this ->customerRepository ->get ('customer@example.com ' );
947
+ $ searchCriteria = $ this ->searchCriteriaBuilder ->addFilter ('parent_id ' , $ customer ->getId ())->create ();
948
+ $ addresses = $ this ->customerAddressRepository ->getList ($ searchCriteria )->getItems ();
949
+
950
+ self ::assertCount (1 , $ addresses );
951
+ self ::assertArrayHasKey ('cart ' , $ response ['setBillingAddressOnCart ' ]);
952
+ foreach ($ addresses as $ address ) {
953
+ $ this ->customerAddressRepository ->delete ($ address );
954
+ }
955
+ }
956
+
874
957
/**
875
958
* @magentoApiDataFixture Magento/Customer/_files/customer.php
876
959
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
@@ -1111,4 +1194,88 @@ private function assignQuoteToCustomer(
1111
1194
$ this ->quoteResource ->save ($ quote );
1112
1195
return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
1113
1196
}
1197
+
1198
+ /**
1199
+ * @param string $maskedQuoteId
1200
+ * @param string $shippingMethodCode
1201
+ * @param string $shippingCarrierCode
1202
+ * @return string
1203
+ */
1204
+ private function getSetShippingMethodsQuery (
1205
+ string $ maskedQuoteId ,
1206
+ string $ shippingMethodCode ,
1207
+ string $ shippingCarrierCode
1208
+ ): string {
1209
+ return <<<QUERY
1210
+ mutation {
1211
+ setShippingMethodsOnCart(input:
1212
+ {
1213
+ cart_id: " $ maskedQuoteId",
1214
+ shipping_methods: [{
1215
+ carrier_code: " $ shippingCarrierCode"
1216
+ method_code: " $ shippingMethodCode"
1217
+ }]
1218
+ }) {
1219
+ cart {
1220
+ shipping_addresses {
1221
+ selected_shipping_method {
1222
+ carrier_code
1223
+ method_code
1224
+ carrier_title
1225
+ method_title
1226
+ amount {
1227
+ value
1228
+ currency
1229
+ }
1230
+ }
1231
+ }
1232
+ }
1233
+ }
1234
+ }
1235
+ QUERY ;
1236
+ }
1237
+
1238
+ /**
1239
+ * @param string $maskedQuoteId
1240
+ * @param string $methodCode
1241
+ * @return string
1242
+ */
1243
+ private function getSetPaymentMethodQuery (
1244
+ string $ maskedQuoteId ,
1245
+ string $ methodCode
1246
+ ) : string {
1247
+ return <<<QUERY
1248
+ mutation {
1249
+ setPaymentMethodOnCart(input: {
1250
+ cart_id: " $ maskedQuoteId"
1251
+ payment_method: {
1252
+ code: " $ methodCode"
1253
+ }
1254
+ }) {
1255
+ cart {
1256
+ selected_payment_method {
1257
+ code
1258
+ }
1259
+ }
1260
+ }
1261
+ }
1262
+ QUERY ;
1263
+ }
1264
+
1265
+ /**
1266
+ * @param string $maskedQuoteId
1267
+ * @return string
1268
+ */
1269
+ private function getPlaceOrderQuery (string $ maskedQuoteId ): string
1270
+ {
1271
+ return <<<QUERY
1272
+ mutation {
1273
+ placeOrder(input: {cart_id: " {$ maskedQuoteId }"}) {
1274
+ order {
1275
+ order_number
1276
+ }
1277
+ }
1278
+ }
1279
+ QUERY ;
1280
+ }
1114
1281
}
0 commit comments