Skip to content

Commit c872e57

Browse files
authored
Merge pull request #244 from woocommerce/issue/240-support-empty-addresses
Support empty shipping and billing addresses
2 parents add0dca + 5719dce commit c872e57

File tree

8 files changed

+47
-50
lines changed

8 files changed

+47
-50
lines changed

WooCommerce/Classes/Model/Order+Woo.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,4 @@ extension Order {
1414

1515
return NSLocale(localeIdentifier: identifier).currencySymbol
1616
}
17-
18-
/// FIXME: Creates an empty-string value Billing details, until i6 fix
19-
///
20-
func generateEmptyBillingAddress() -> Address {
21-
return Address(firstName: "", lastName: "", company: "", address1: "", address2: "", city: "", state: "", postcode: "", country: "", phone: "", email: "")
22-
}
2317
}

WooCommerce/Classes/ViewModels/OrderDetailsViewModel.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,20 @@ class OrderDetailsViewModel {
6262
return order.customerNote ?? String()
6363
}
6464

65-
var shippingViewModel: ContactViewModel {
65+
var shippingViewModel: ContactViewModel? {
6666
if let shippingAddress = order.shippingAddress {
6767
return ContactViewModel(with: shippingAddress, contactType: ContactType.shipping)
6868
}
6969

70-
if let billingAddress = order.billingAddress {
71-
return ContactViewModel(with: billingAddress, contactType: ContactType.shipping)
72-
}
73-
74-
return ContactViewModel(with: order.generateEmptyBillingAddress(), contactType: ContactType.shipping)
75-
}
76-
var shippingAddress: String? {
77-
return shippingViewModel.formattedAddress
70+
return nil
7871
}
7972

8073
var billingViewModel: ContactViewModel? {
8174
if let billingAddress = order.billingAddress {
8275
return ContactViewModel(with: billingAddress, contactType: ContactType.billing)
8376
}
84-
return nil
85-
}
8677

87-
var billingAddress: String? {
88-
return billingViewModel?.formattedAddress
78+
return nil
8979
}
9080

9181
let subtotalLabel = NSLocalizedString("Subtotal", comment: "Subtotal label for payment view")

WooCommerce/Classes/ViewRelated/Orders/FulfillViewController.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,14 @@ private extension FulfillViewController {
252252

253253
/// Setup: Address Cell
254254
///
255-
private func setupAddressCell(_ cell: UITableViewCell, with address: Address) {
255+
private func setupAddressCell(_ cell: UITableViewCell, with address: Address?) {
256256
guard let cell = cell as? CustomerInfoTableViewCell else {
257257
fatalError()
258258
}
259259

260260
guard let address = order.shippingAddress ?? order.billingAddress else {
261+
cell.title = NSLocalizedString("Shipping details", comment: "Shipping title for customer info cell")
262+
cell.address = NSLocalizedString("No address specified.", comment: "Fulfill order > customer info > where the address would normally display.")
261263
return
262264
}
263265

@@ -303,7 +305,7 @@ private enum Row {
303305

304306
/// Represents an Address Row
305307
///
306-
case address(shipping: Address)
308+
case address(shipping: Address?)
307309

308310
/// Represents an "Add Tracking" Row
309311
///
@@ -385,14 +387,7 @@ private extension Section {
385387
return Section(title: title, secondaryTitle: nil, rows: [row])
386388
}
387389

388-
if let billingAddress = order.billingAddress {
389-
let row = Row.address(shipping: billingAddress)
390-
391-
return Section(title: title, secondaryTitle: nil, rows: [row])
392-
}
393-
394-
let emptyAddress = order.generateEmptyBillingAddress()
395-
let row = Row.address(shipping: emptyAddress)
390+
let row = Row.address(shipping: order.billingAddress)
396391

397392
return Section(title: title, secondaryTitle: nil, rows: [row])
398393
}()

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/BillingDetailsTableViewCell.xib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
1919
<autoresizingMask key="autoresizingMask"/>
2020
<subviews>
21-
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="drm-Ej-5OZ">
21+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="drm-Ej-5OZ">
2222
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
2323
<autoresizingMask key="autoresizingMask"/>
2424
<fontDescription key="fontDescription" type="system" pointSize="17"/>

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/CustomerInfoTableViewCell.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,3 @@ class CustomerInfoTableViewCell: UITableViewCell {
4545
}
4646
}
4747
}
48-
49-
extension CustomerInfoTableViewCell {
50-
func configure(with viewModel: ContactViewModel) {
51-
title = viewModel.title
52-
name = viewModel.fullName
53-
address = viewModel.formattedAddress
54-
}
55-
}

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/CustomerInfoTableViewCell.xib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
<nil key="textColor"/>
2828
<nil key="highlightedColor"/>
2929
</label>
30-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="First name Last name" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pQe-4r-eVj">
31-
<rect key="frame" x="0.0" y="20.5" width="280" height="20.5"/>
30+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pQe-4r-eVj" userLabel="Full name Label">
31+
<rect key="frame" x="0.0" y="20.5" width="280" height="0.0"/>
3232
<fontDescription key="fontDescription" type="system" pointSize="17"/>
3333
<nil key="textColor"/>
3434
<nil key="highlightedColor"/>
3535
</label>
3636
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="240" text="Multiline, localized address that uses cnpostaladdressformatter" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KJW-Ch-VgS">
37-
<rect key="frame" x="0.0" y="41" width="280" height="48.5"/>
37+
<rect key="frame" x="0.0" y="20.5" width="280" height="69"/>
3838
<fontDescription key="fontDescription" type="system" pointSize="17"/>
3939
<nil key="textColor"/>
4040
<nil key="highlightedColor"/>

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/OrderDetailsViewController.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,14 @@ private extension OrderDetailsViewController {
125125
let customerNoteSection = Section(leftTitle: NSLocalizedString("CUSTOMER PROVIDED NOTE", comment: "Customer note section title"), rightTitle: nil, footer: nil, rows: [.customerNote])
126126

127127
let infoFooter = billingIsHidden ? NSLocalizedString("Show billing", comment: "Footer text to show the billing cell") : NSLocalizedString("Hide billing", comment: "Footer text to hide the billing cell")
128-
let infoRows: [Row] = billingIsHidden ? [.shippingAddress] : [.shippingAddress, .billingAddress, .billingPhone, .billingEmail]
128+
var infoRows: [Row] = [Row]()
129+
if billingIsHidden {
130+
infoRows = [.shippingAddress]
131+
} else if viewModel.order.billingAddress == nil {
132+
infoRows = [.shippingAddress, .billingAddress]
133+
} else {
134+
infoRows = [.shippingAddress, .billingAddress, .billingPhone, .billingEmail]
135+
}
129136
let infoSection = Section(leftTitle: NSLocalizedString("CUSTOMER INFORMATION", comment: "Customer info section title"), rightTitle: nil, footer: infoFooter, rows: infoRows)
130137
let paymentSection = Section(leftTitle: NSLocalizedString("PAYMENT", comment: "Payment section title"), rightTitle: nil, footer: nil, rows: [.payment])
131138

@@ -243,13 +250,24 @@ private extension OrderDetailsViewController {
243250
case let cell as CustomerNoteTableViewCell:
244251
cell.configure(with: viewModel)
245252
case let cell as CustomerInfoTableViewCell where row == .shippingAddress:
246-
cell.configure(with: viewModel.shippingViewModel)
253+
if let shippingViewModel = viewModel.shippingViewModel {
254+
cell.title = shippingViewModel.title
255+
cell.name = shippingViewModel.fullName
256+
cell.address = shippingViewModel.formattedAddress
257+
} else {
258+
cell.title = NSLocalizedString("Shipping details", comment: "Shipping title for customer info cell")
259+
cell.name = nil
260+
cell.address = NSLocalizedString("No address specified.", comment: "Order details > customer info > shipping details. This is where the address would normally display.")
261+
}
247262
case let cell as CustomerInfoTableViewCell where row == .billingAddress:
248263
if let billingViewModel = viewModel.billingViewModel {
249-
cell.configure(with: billingViewModel)
264+
cell.title = billingViewModel.title
265+
cell.name = billingViewModel.fullName
266+
cell.address = billingViewModel.formattedAddress
250267
} else {
251-
let billingViewModel = ContactViewModel(with: viewModel.order.generateEmptyBillingAddress(), contactType: ContactType.billing)
252-
cell.configure(with: billingViewModel)
268+
cell.title = NSLocalizedString("Billing details", comment: "Billing title for customer info cell")
269+
cell.name = nil
270+
cell.address = NSLocalizedString("No address specified.", comment: "Order details > customer info > billing details. This is where the address would normally display.")
253271
}
254272
case let cell as BillingDetailsTableViewCell where row == .billingPhone:
255273
configure(cell, for: .billingPhone)

Yosemite/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ extension Storage.Order: ReadOnlyConvertible {
9292

9393
// MARK: - Private Helpers
9494

95-
private func createReadOnlyBillingAddress() -> Yosemite.Address {
95+
private func createReadOnlyBillingAddress() -> Yosemite.Address? {
96+
guard let billingCountry = billingCountry else {
97+
return nil
98+
}
99+
96100
return Address(firstName: billingFirstName ?? "",
97101
lastName: billingLastName ?? "",
98102
company: billingCompany ?? "",
@@ -101,12 +105,16 @@ extension Storage.Order: ReadOnlyConvertible {
101105
city: billingCity ?? "",
102106
state: billingState ?? "",
103107
postcode: billingPostcode ?? "",
104-
country: billingCountry ?? "",
108+
country: billingCountry,
105109
phone: billingPhone ?? "",
106110
email: billingEmail ?? "")
107111
}
108112

109-
private func createReadOnlyShippingAddress() -> Yosemite.Address {
113+
private func createReadOnlyShippingAddress() -> Yosemite.Address? {
114+
guard let shippingCountry = shippingCountry else {
115+
return nil
116+
}
117+
110118
return Address(firstName: shippingFirstName ?? "",
111119
lastName: shippingLastName ?? "",
112120
company: shippingCompany ?? "",
@@ -115,7 +123,7 @@ extension Storage.Order: ReadOnlyConvertible {
115123
city: shippingCity ?? "",
116124
state: shippingState ?? "",
117125
postcode: shippingPostcode ?? "",
118-
country: shippingCountry ?? "",
126+
country: shippingCountry,
119127
phone: shippingPhone ?? "",
120128
email: shippingEmail ?? "")
121129
}

0 commit comments

Comments
 (0)