@@ -131,3 +131,164 @@ private extension ShippingLabelPackagesFormViewModel {
131131 stores. dispatch ( action)
132132 }
133133}
134+
135+ // MARK: - Methods for rendering a SwiftUI Preview
136+ //
137+ extension ShippingLabelPackagesFormViewModel {
138+
139+ static func sampleOrder( ) -> Order {
140+ return Order ( siteID: 1234 ,
141+ orderID: 963 ,
142+ parentID: 0 ,
143+ customerID: 11 ,
144+ number: " 963 " ,
145+ status: . processing,
146+ currency: " USD " ,
147+ customerNote: " " ,
148+ dateCreated: date ( with: " 2018-04-03T23:05:12 " ) ,
149+ dateModified: date ( with: " 2018-04-03T23:05:14 " ) ,
150+ datePaid: date ( with: " 2018-04-03T23:05:14 " ) ,
151+ discountTotal: " 30.00 " ,
152+ discountTax: " 1.20 " ,
153+ shippingTotal: " 0.00 " ,
154+ shippingTax: " 0.00 " ,
155+ total: " 31.20 " ,
156+ totalTax: " 1.20 " ,
157+ paymentMethodID: " stripe " ,
158+ paymentMethodTitle: " Credit Card (Stripe) " ,
159+ items: sampleItems ( ) ,
160+ billingAddress: sampleAddress ( ) ,
161+ shippingAddress: sampleAddress ( ) ,
162+ shippingLines: sampleShippingLines ( ) ,
163+ coupons: sampleCoupons ( ) ,
164+ refunds: [ ] ,
165+ fees: [ ] )
166+ }
167+
168+ static func sampleAddress( ) -> Address {
169+ return Address ( firstName: " Johnny " ,
170+ lastName: " Appleseed " ,
171+ company: " " ,
172+ address1: " 234 70th Street " ,
173+ address2: " " ,
174+ city: " Niagara Falls " ,
175+ state: " NY " ,
176+ postcode: " 14304 " ,
177+ country: " US " ,
178+ phone: " 333-333-3333 " ,
179+ 180+ }
181+
182+ static func sampleShippingLines( ) -> [ ShippingLine ] {
183+ return [ ShippingLine ( shippingID: 123 ,
184+ methodTitle: " International Priority Mail Express Flat Rate " ,
185+ methodID: " usps " ,
186+ total: " 133.00 " ,
187+ totalTax: " 0.00 " ,
188+ taxes: [ . init( taxID: 1 , subtotal: " " , total: " 0.62125 " ) ] ) ]
189+ }
190+
191+ static func sampleCoupons( ) -> [ OrderCouponLine ] {
192+ let coupon1 = OrderCouponLine ( couponID: 894 ,
193+ code: " 30$off " ,
194+ discount: " 30 " ,
195+ discountTax: " 1.2 " )
196+
197+ return [ coupon1]
198+ }
199+
200+ static func sampleItems( ) -> [ OrderItem ] {
201+ let item1 = OrderItem ( itemID: 890 ,
202+ name: " Fruits Basket (Mix & Match Product) " ,
203+ productID: 52 ,
204+ variationID: 0 ,
205+ quantity: 2 ,
206+ price: NSDecimalNumber ( integerLiteral: 30 ) ,
207+ sku: " " ,
208+ subtotal: " 50.00 " ,
209+ subtotalTax: " 2.00 " ,
210+ taxClass: " " ,
211+ taxes: [ . init( taxID: 1 , subtotal: " 2 " , total: " 1.2 " ) ] ,
212+ total: " 30.00 " ,
213+ totalTax: " 1.20 " ,
214+ attributes: [ ] )
215+
216+ let item2 = OrderItem ( itemID: 891 ,
217+ name: " Fruits Bundle " ,
218+ productID: 234 ,
219+ variationID: 0 ,
220+ quantity: 1.5 ,
221+ price: NSDecimalNumber ( integerLiteral: 0 ) ,
222+ sku: " 5555-A " ,
223+ subtotal: " 10.00 " ,
224+ subtotalTax: " 0.40 " ,
225+ taxClass: " " ,
226+ taxes: [ . init( taxID: 1 , subtotal: " 0.4 " , total: " 0 " ) ] ,
227+ total: " 0.00 " ,
228+ totalTax: " 0.00 " ,
229+ attributes: [ ] )
230+
231+ return [ item1, item2]
232+ }
233+
234+ static func date( with dateString: String ) -> Date {
235+ guard let date = DateFormatter . Defaults. dateTimeFormatter. date ( from: dateString) else {
236+ return Date ( )
237+ }
238+ return date
239+ }
240+
241+ static func taxes( ) -> [ OrderItemTax ] {
242+ return [ OrderItemTax ( taxID: 75 , subtotal: " 0.45 " , total: " 0.45 " ) ]
243+ }
244+
245+ static func samplePackageDetails( ) -> ShippingLabelPackagesResponse {
246+ return ShippingLabelPackagesResponse ( storeOptions: sampleShippingLabelStoreOptions ( ) ,
247+ customPackages: sampleShippingLabelCustomPackages ( ) ,
248+ predefinedOptions: sampleShippingLabelPredefinedOptions ( ) ,
249+ unactivatedPredefinedOptions: sampleShippingLabelPredefinedOptions ( ) )
250+ }
251+
252+ static func sampleShippingLabelStoreOptions( ) -> ShippingLabelStoreOptions {
253+ return ShippingLabelStoreOptions ( currencySymbol: " $ " , dimensionUnit: " cm " , weightUnit: " kg " , originCountry: " US " )
254+ }
255+
256+ static func sampleShippingLabelCustomPackages( ) -> [ ShippingLabelCustomPackage ] {
257+ let customPackage1 = ShippingLabelCustomPackage ( isUserDefined: true ,
258+ title: " Krabica " ,
259+ isLetter: false ,
260+ dimensions: " 1 x 2 x 3 " ,
261+ boxWeight: 1 ,
262+ maxWeight: 0 )
263+ let customPackage2 = ShippingLabelCustomPackage ( isUserDefined: true ,
264+ title: " Obalka " ,
265+ isLetter: true ,
266+ dimensions: " 2 x 3 x 4 " ,
267+ boxWeight: 5 ,
268+ maxWeight: 0 )
269+
270+ return [ customPackage1, customPackage2]
271+ }
272+
273+ static func sampleShippingLabelPredefinedOptions( ) -> [ ShippingLabelPredefinedOption ] {
274+ let predefinedPackages1 = [ ShippingLabelPredefinedPackage ( id: " small_flat_box " ,
275+ title: " Small Flat Rate Box " ,
276+ isLetter: false ,
277+ dimensions: " 21.91 x 13.65 x 4.13 " ) ,
278+ ShippingLabelPredefinedPackage ( id: " medium_flat_box_top " ,
279+ title: " Medium Flat Rate Box 1, Top Loading " ,
280+ isLetter: false ,
281+ dimensions: " 28.57 x 22.22 x 15.24 " ) ]
282+ let predefinedOption1 = ShippingLabelPredefinedOption ( title: " USPS Priority Mail Flat Rate Boxes " ,
283+ predefinedPackages: predefinedPackages1)
284+
285+ let predefinedPackages2 = [ ShippingLabelPredefinedPackage ( id: " LargePaddedPouch " ,
286+ title: " Large Padded Pouch " ,
287+ isLetter: true ,
288+ dimensions: " 30.22 x 35.56 x 2.54 " ) ]
289+ let predefinedOption2 = ShippingLabelPredefinedOption ( title: " DHL Express " ,
290+ predefinedPackages: predefinedPackages2)
291+
292+ return [ predefinedOption1, predefinedOption2]
293+ }
294+ }
0 commit comments