@@ -41,6 +41,8 @@ protected function prepareOrder()
41
41
$ orderPaymentFactory = $ this ->objectManager ->get (\Magento \Sales \Model \Order \PaymentFactory::class);
42
42
/** @var \Magento\Sales\Model\Order\AddressRepository $orderAddressRepository */
43
43
$ orderAddressRepository = $ this ->objectManager ->get (\Magento \Sales \Model \Order \AddressRepository::class);
44
+ /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
45
+ $ storeManager = $ this ->objectManager ->get (\Magento \Store \Model \StoreManagerInterface::class);
44
46
45
47
$ order = $ orderFactory ->create (
46
48
['data ' => $ this ->getDataStructure (\Magento \Sales \Api \Data \OrderInterface::class)]
@@ -68,9 +70,36 @@ protected function prepareOrder()
68
70
$ order ->setCustomerEmail ($ email );
69
71
$ order ->setBaseGrandTotal (100 );
70
72
$ order ->setGrandTotal (100 );
73
+ $ order ->setShippingDescription ('Flat Rate - Fixed ' );
74
+ $ order ->setIsVirtual (0 );
75
+ $ order ->setStoreId ($ storeManager ->getDefaultStoreView ()->getId ());
76
+ $ order ->setBaseDiscountAmount (0 );
77
+ $ order ->setBaseShippingAmount (5 );
78
+ $ order ->setBaseShippingTaxAmount (0 );
79
+ $ order ->setBaseSubtotal (100 );
80
+ $ order ->setBaseTaxAmount (0 );
81
+ $ order ->setBaseToGlobalRate (1 );
82
+ $ order ->setBaseToOrderRate (1 );
83
+ $ order ->setDiscountAmount (0 );
84
+ $ order ->setShippingAmount (0 );
85
+ $ order ->setShippingTaxAmount (0 );
86
+ $ order ->setStoreToOrderRate (0 );
87
+ $ order ->setBaseToOrderRate (0 );
88
+ $ order ->setSubtotal (100 );
89
+ $ order ->setTaxAmount (0 );
90
+ $ order ->setTotalQtyOrdered (1 );
91
+ $ order ->setCustomerIsGuest (1 );
92
+ $ order ->setCustomerNoteNotify (0 );
93
+ $ order ->setCustomerGroupId (0 );
94
+ $ order ->setBaseSubtotalInclTax (100 );
95
+ $ order ->setWeight (1 );
96
+ $ order ->setBaseCurrencyCode ('USD ' );
97
+ $ order ->setShippingInclTax (5 );
98
+ $ order ->setBaseShippingInclTax (5 );
71
99
72
100
$ this ->addProductOption ($ orderItem );
73
101
102
+
74
103
$ order ->setItems ([$ orderItem ->getData ()]);
75
104
$ order ->setData ('payment ' , $ orderPayment ->getData ());
76
105
@@ -82,12 +111,37 @@ protected function prepareOrder()
82
111
$ orderAddressBilling ->setFirstname ('First Name ' );
83
112
$ orderAddressBilling ->setTelephone ('+00(000)-123-45-57 ' );
84
113
$ orderAddressBilling ->setStreet (['Street ' ]);
85
- $ orderAddressBilling ->setCountryId (1 );
114
+ $ orderAddressBilling ->setCountryId ('US ' );
115
+ $ orderAddressBilling ->setRegion ('California ' );
86
116
$ orderAddressBilling ->setAddressType ('billing ' );
117
+ $ orderAddressBilling ->setRegionId (12 );
118
+
119
+ $ orderAddressShipping = $ orderAddressRepository ->create ();
120
+ $ orderAddressShipping ->setCity ('City2 ' );
121
+ $ orderAddressShipping ->setPostcode ('12345 ' );
122
+ $ orderAddressShipping ->setLastname ('Last Name2 ' );
123
+ $ orderAddressShipping ->setFirstname ('First Name2 ' );
124
+ $ orderAddressShipping ->setTelephone ('+00(000)-123-45-57 ' );
125
+ $ orderAddressShipping ->setStreet (['Street ' ]);
126
+ $ orderAddressShipping ->setCountryId ('US ' );
127
+ $ orderAddressShipping ->setRegion ('California ' );
128
+ $ orderAddressShipping ->setAddressType ('shipping ' );
129
+ $ orderAddressShipping ->setRegionId (12 );
87
130
88
131
$ orderData = $ order ->getData ();
89
132
$ orderData ['billing_address ' ] = $ orderAddressBilling ->getData ();
90
133
$ orderData ['billing_address ' ]['street ' ] = ['Street ' ];
134
+ $ address = $ orderAddressShipping ->getData ();
135
+ $ address ['street ' ] = ['Street ' ];
136
+ $ orderData ['extension_attributes ' ]['shipping_assignments ' ] =
137
+ [
138
+ [
139
+ 'shipping ' => [
140
+ 'address ' => $ address ,
141
+ 'method ' => 'Flat Rate - Fixed '
142
+ ]
143
+ ]
144
+ ];
91
145
return $ orderData ;
92
146
}
93
147
@@ -172,5 +226,8 @@ public function testOrderCreate()
172
226
$ this ->assertTrue ((bool )$ model ->getId ());
173
227
$ this ->assertEquals ($ order ['base_grand_total ' ], $ model ->getBaseGrandTotal ());
174
228
$ this ->assertEquals ($ order ['grand_total ' ], $ model ->getGrandTotal ());
229
+ $ this ->assertNotNull ($ model ->getShippingAddress ());
230
+ $ this ->assertTrue ((bool )$ model ->getShippingAddress ()->getId ());
231
+ $ this ->assertEquals ('Flat Rate - Fixed ' , $ model ->getShippingMethod ());
175
232
}
176
233
}
0 commit comments