|
| 1 | +import Foundation |
| 2 | +import Storage |
| 3 | + |
| 4 | + |
| 5 | +// MARK: - Storage.order: ReadOnlyConvertible |
| 6 | +// |
| 7 | +extension Storage.Order: ReadOnlyConvertible { |
| 8 | + |
| 9 | + /// Updates the Storage.Order with the a ReadOnly. |
| 10 | + /// |
| 11 | + public func update(with order: Yosemite.Order) { |
| 12 | + orderID = Int64(order.orderID) |
| 13 | + parentID = Int64(order.parentID) |
| 14 | + customerID = Int64(order.customerID) |
| 15 | + number = order.number |
| 16 | + status = order.status.rawValue |
| 17 | + currency = order.currency |
| 18 | + customerNote = order.customerNote |
| 19 | + dateCreated = order.dateCreated |
| 20 | + dateModified = order.dateModified |
| 21 | + datePaid = order.datePaid |
| 22 | + discountTotal = order.discountTotal |
| 23 | + discountTax = order.discountTax |
| 24 | + shippingTotal = order.shippingTotal |
| 25 | + shippingTax = order.shippingTax |
| 26 | + total = order.total |
| 27 | + totalTax = order.totalTax |
| 28 | + paymentMethodTitle = order.paymentMethodTitle |
| 29 | + |
| 30 | + // TODO: items, coupons, billing address, and shipping address |
| 31 | + } |
| 32 | + |
| 33 | + /// Returns a ReadOnly version of the receiver. |
| 34 | + /// |
| 35 | + public func toReadOnly() -> Yosemite.Order { |
| 36 | + return Order(orderID: Int(orderID), |
| 37 | + parentID: Int(parentID), |
| 38 | + customerID: Int(customerID), |
| 39 | + number: number ?? "", |
| 40 | + status: OrderStatus(rawValue: status), |
| 41 | + currency: currency ?? "", |
| 42 | + customerNote: customerNote ?? "", |
| 43 | + dateCreated: dateCreated ?? Date(), |
| 44 | + dateModified: dateModified ?? Date(), |
| 45 | + datePaid: datePaid ?? Date(), |
| 46 | + discountTotal: discountTotal ?? "", |
| 47 | + discountTax: discountTax ?? "", |
| 48 | + shippingTotal: shippingTotal ?? "", |
| 49 | + shippingTax: shippingTax ?? "", |
| 50 | + total: total ?? "", |
| 51 | + totalTax: totalTax ?? "", |
| 52 | + paymentMethodTitle: paymentMethodTitle ?? "", |
| 53 | + items: [], |
| 54 | + billingAddress: blankAddress(), |
| 55 | + shippingAddress: blankAddress(), |
| 56 | + coupons: []) |
| 57 | + |
| 58 | + // TODO: ^^^^ items, coupons, billing address, and shipping address ^^^^ |
| 59 | + } |
| 60 | + |
| 61 | + private func blankAddress() -> Yosemite.Address { |
| 62 | + return Address(firstName: "", |
| 63 | + lastName: "", |
| 64 | + company: "", |
| 65 | + address1: "", |
| 66 | + address2: "", |
| 67 | + city: "", |
| 68 | + state: "", |
| 69 | + postcode: "", |
| 70 | + country: "", |
| 71 | + phone: "", |
| 72 | + email: "") |
| 73 | + } |
| 74 | +} |
0 commit comments