Skip to content

Commit 01c5db0

Browse files
authored
Merge pull request #139 from woocommerce/feature/102-orders-yosemite-mark3
Yosemite Integration for Orders: Mark 3
2 parents a12793a + 8816103 commit 01c5db0

File tree

22 files changed

+351
-2631
lines changed

22 files changed

+351
-2631
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
21DB5B99C4107CF69C0A57EC /* Pods_NetworkingTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69314EDE650855CAF927057E /* Pods_NetworkingTests.framework */; };
1111
6647C0161DAC6AB6570C53A7 /* Pods_Networking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3F25DC15EC1D7C631169CB5 /* Pods_Networking.framework */; };
12+
741B950120EBC8A700DD6E2D /* OrderCouponLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 741B950020EBC8A700DD6E2D /* OrderCouponLine.swift */; };
1213
B505F6CD20BEE37E00BB1B69 /* AccountMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6CC20BEE37E00BB1B69 /* AccountMapper.swift */; };
1314
B505F6CF20BEE38B00BB1B69 /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6CE20BEE38B00BB1B69 /* Account.swift */; };
1415
B505F6D120BEE39600BB1B69 /* AccountRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D020BEE39600BB1B69 /* AccountRemote.swift */; };
@@ -63,6 +64,7 @@
6364

6465
/* Begin PBXFileReference section */
6566
69314EDE650855CAF927057E /* Pods_NetworkingTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NetworkingTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
67+
741B950020EBC8A700DD6E2D /* OrderCouponLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCouponLine.swift; sourceTree = "<group>"; };
6668
753D6504FF01F09F6A33B73E /* Pods-Networking.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Networking.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Networking/Pods-Networking.debug.xcconfig"; sourceTree = "<group>"; };
6769
B505F6CC20BEE37E00BB1B69 /* AccountMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountMapper.swift; sourceTree = "<group>"; };
6870
B505F6CE20BEE38B00BB1B69 /* Account.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
@@ -277,6 +279,7 @@
277279
children = (
278280
B505F6CE20BEE38B00BB1B69 /* Account.swift */,
279281
B5BB1D0F20A237FB00112D92 /* Address.swift */,
282+
741B950020EBC8A700DD6E2D /* OrderCouponLine.swift */,
280283
B557DA1C20979E7D005962F4 /* Order.swift */,
281284
B5BB1D1120A255EC00112D92 /* OrderStatus.swift */,
282285
B5C6FCCE20A3592900A4F8E4 /* OrderItem.swift */,
@@ -518,6 +521,7 @@
518521
buildActionMask = 2147483647;
519522
files = (
520523
B557DA1A20979D66005962F4 /* Settings.swift in Sources */,
524+
741B950120EBC8A700DD6E2D /* OrderCouponLine.swift in Sources */,
521525
B5BB1D0C20A2050300112D92 /* DateFormatter+Woo.swift in Sources */,
522526
B567AF2520A0CCA300AB6C62 /* AuthenticatedRequest.swift in Sources */,
523527
B505F6EA20BEFC3700BB1B69 /* MockupNetwork.swift in Sources */,

Networking/Networking/Model/Order.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ public struct Order: Decodable {
2323
public let shippingTax: String
2424
public let total: String
2525
public let totalTax: String
26+
public let paymentMethodTitle: String
2627

2728
public let items: [OrderItem]
2829
public let billingAddress: Address
2930
public let shippingAddress: Address
31+
public let coupons: [OrderCouponLine]
3032

3133
/// Order struct initializer.
3234
///
33-
init(orderID: Int, parentID: Int, customerID: Int, number: String, status: OrderStatus, currency: String, customerNote: String?, dateCreated: Date, dateModified: Date, datePaid: Date?, discountTotal: String, discountTax: String, shippingTotal: String, shippingTax: String, total: String, totalTax: String, items: [OrderItem], billingAddress: Address, shippingAddress: Address) {
35+
init(orderID: Int, parentID: Int, customerID: Int, number: String, status: OrderStatus, currency: String, customerNote: String?, dateCreated: Date, dateModified: Date, datePaid: Date?, discountTotal: String, discountTax: String, shippingTotal: String, shippingTax: String, total: String, totalTax: String, paymentMethodTitle: String, items: [OrderItem], billingAddress: Address, shippingAddress: Address, coupons: [OrderCouponLine]) {
36+
3437
self.orderID = orderID
3538
self.parentID = parentID
3639
self.customerID = customerID
@@ -50,10 +53,12 @@ public struct Order: Decodable {
5053
self.shippingTax = shippingTax
5154
self.total = total
5255
self.totalTax = totalTax
56+
self.paymentMethodTitle = paymentMethodTitle
5357

5458
self.items = items
5559
self.billingAddress = billingAddress
5660
self.shippingAddress = shippingAddress
61+
self.coupons = coupons
5762
}
5863

5964

@@ -80,12 +85,14 @@ public struct Order: Decodable {
8085
let shippingTotal = try container.decode(String.self, forKey: .shippingTotal)
8186
let total = try container.decode(String.self, forKey: .total)
8287
let totalTax = try container.decode(String.self, forKey: .totalTax)
88+
let paymentMethodTitle = try container.decode(String.self, forKey: .paymentMethodTitle)
8389

8490
let items = try container.decode([OrderItem].self, forKey: .items)
8591
let shippingAddress = try container.decode(Address.self, forKey: .shippingAddress)
8692
let billingAddress = try container.decode(Address.self, forKey: .billingAddress)
93+
let coupons = try container.decode([OrderCouponLine].self, forKey: .couponLines)
8794

88-
self.init(orderID: orderID, parentID: parentID, customerID: customerID, number: number, status: status, currency: currency, customerNote: customerNote, dateCreated: dateCreated, dateModified: dateModified, datePaid: datePaid, discountTotal: discountTotal, discountTax: discountTax, shippingTotal: shippingTotal, shippingTax: shippingTax, total: total, totalTax: totalTax, items: items, billingAddress: billingAddress, shippingAddress: shippingAddress) // initialize the struct
95+
self.init(orderID: orderID, parentID: parentID, customerID: customerID, number: number, status: status, currency: currency, customerNote: customerNote, dateCreated: dateCreated, dateModified: dateModified, datePaid: datePaid, discountTotal: discountTotal, discountTax: discountTax, shippingTotal: shippingTotal, shippingTax: shippingTax, total: total, totalTax: totalTax, paymentMethodTitle: paymentMethodTitle, items: items, billingAddress: billingAddress, shippingAddress: shippingAddress, coupons: coupons) // initialize the struct
8996
}
9097
}
9198

@@ -114,10 +121,12 @@ private extension Order {
114121
case shippingTax = "shipping_tax"
115122
case total = "total"
116123
case totalTax = "total_tax"
124+
case paymentMethodTitle = "payment_method_title"
117125

118126
case items = "line_items"
119127
case shippingAddress = "shipping"
120128
case billingAddress = "billing"
129+
case couponLines = "coupon_lines"
121130
}
122131
}
123132

@@ -140,8 +149,10 @@ extension Order: Comparable {
140149
lhs.shippingTax == rhs.shippingTax &&
141150
lhs.total == rhs.total &&
142151
lhs.totalTax == rhs.totalTax &&
152+
lhs.paymentMethodTitle == rhs.paymentMethodTitle &&
143153
lhs.billingAddress == rhs.billingAddress &&
144154
lhs.shippingAddress == rhs.shippingAddress &&
155+
lhs.coupons == rhs.coupons &&
145156
lhs.items.count == rhs.items.count &&
146157
lhs.items.sorted() == rhs.items.sorted()
147158
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Foundation
2+
3+
4+
/// Represents a CouponLine Entity within an Order.
5+
///
6+
public struct OrderCouponLine: Decodable {
7+
public let couponID: Int
8+
public let code: String
9+
public let discount: String
10+
public let discountTax: String
11+
}
12+
13+
14+
/// Defines all of the CouponLine's CodingKeys.
15+
///
16+
private extension OrderCouponLine {
17+
18+
enum CodingKeys: String, CodingKey {
19+
case couponID = "id"
20+
case code = "code"
21+
case discount = "discount"
22+
case discountTax = "discount_tax"
23+
}
24+
}
25+
26+
27+
// MARK: - Comparable Conformance
28+
//
29+
extension OrderCouponLine: Comparable {
30+
public static func == (lhs: OrderCouponLine, rhs: OrderCouponLine) -> Bool {
31+
return lhs.couponID == rhs.couponID &&
32+
lhs.code == rhs.code &&
33+
lhs.discount == rhs.discount &&
34+
lhs.discountTax == rhs.discountTax
35+
}
36+
37+
public static func < (lhs: OrderCouponLine, rhs: OrderCouponLine) -> Bool {
38+
return lhs.couponID < rhs.couponID ||
39+
(lhs.couponID == rhs.couponID && lhs.code < rhs.code) ||
40+
(lhs.couponID == rhs.couponID && lhs.code == rhs.code && lhs.discount < rhs.discount)
41+
}
42+
}

WooCommerce/Classes/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3131

3232

3333

34-
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
34+
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
3535

3636
// Setup the Interface!
3737
setupMainWindow()

WooCommerce/Classes/Extensions/CNContact+Helpers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Foundation
22
import Contacts
3+
import Yosemite
4+
35

46
extension CNContact {
57
static func from(address: Address) -> CNContact {

WooCommerce/Classes/Extensions/UILabel+Helpers.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import UIKit
2+
import Yosemite
3+
24

35
extension UILabel {
46
func applyTitleStyle() {
@@ -19,7 +21,7 @@ extension UILabel {
1921
func applyStatusStyle(for status: OrderStatus) {
2022
layer.borderWidth = 1.0
2123
layer.cornerRadius = 4.0
22-
font = .footnote;
24+
font = .footnote
2325

2426
switch status {
2527
case .processing:
@@ -37,7 +39,7 @@ extension UILabel {
3739
layer.borderColor = StyleManager.statusPrimaryBoldColor.cgColor
3840
case .onHold:
3941
fallthrough
40-
case .canceled:
42+
case .cancelled:
4143
fallthrough
4244
case .custom:
4345
fallthrough
@@ -50,6 +52,6 @@ extension UILabel {
5052
func applyPaddedLabelDefaultStyles() {
5153
layer.borderWidth = 1.0
5254
layer.cornerRadius = 4.0
53-
font = .footnote;
55+
font = .footnote
5456
}
5557
}

0 commit comments

Comments
 (0)