Skip to content

Commit a15922a

Browse files
committed
Add shipping row to the payment section of the new order screen
1 parent afc0982 commit a15922a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrderViewModel.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,17 @@ extension NewOrderViewModel {
387387
let itemsTotal: String
388388
let orderTotal: String
389389

390+
let shouldShowShippingTotal: Bool
391+
let shippingTotal: String
392+
390393
init(itemsTotal: String = "",
394+
shouldShowShippingTotal: Bool = false,
395+
shippingTotal: String = "",
391396
orderTotal: String = "",
392397
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings)) {
393398
self.itemsTotal = currencyFormatter.formatAmount(itemsTotal) ?? ""
399+
self.shouldShowShippingTotal = shouldShowShippingTotal
400+
self.shippingTotal = currencyFormatter.formatAmount(shippingTotal) ?? ""
394401
self.orderTotal = currencyFormatter.formatAmount(orderTotal) ?? ""
395402
}
396403
}
@@ -493,10 +500,15 @@ private extension NewOrderViewModel {
493500
.map { $0.orderItem.subtotal }
494501
.compactMap { self.currencyFormatter.convertToDecimal(from: $0) }
495502
.reduce(NSDecimalNumber(value: 0), { $0.adding($1) })
496-
.stringValue
497503

498-
// For now, the order total is the same as the items total
499-
return PaymentDataViewModel(itemsTotal: itemsTotal, orderTotal: itemsTotal, currencyFormatter: self.currencyFormatter)
504+
let shippingTotal = NSDecimalNumber(value: 0)
505+
let orderTotal = itemsTotal.adding(shippingTotal)
506+
507+
return PaymentDataViewModel(itemsTotal: itemsTotal.stringValue,
508+
shouldShowShippingTotal: false,
509+
shippingTotal: shippingTotal.stringValue,
510+
orderTotal: orderTotal.stringValue,
511+
currencyFormatter: self.currencyFormatter)
500512
}
501513
.assign(to: &$paymentDataViewModel)
502514
}

WooCommerce/Classes/ViewRelated/Orders/Order Creation/PaymentSection/OrderPaymentSection.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ struct OrderPaymentSection: View {
2020

2121
TitleAndValueRow(title: Localization.productsTotal, value: .content(viewModel.itemsTotal), selectable: false) {}
2222

23+
if viewModel.shouldShowShippingTotal {
24+
TitleAndValueRow(title: Localization.shippingTotal, value: .content(viewModel.shippingTotal), selectable: true) {
25+
}
26+
} else {
27+
Button(Localization.addShipping) {
28+
}
29+
.buttonStyle(PlusButtonStyle())
30+
.padding()
31+
}
32+
2333
TitleAndValueRow(title: Localization.orderTotal, value: .content(viewModel.orderTotal), bold: true, selectable: false) {}
2434

2535
Text(Localization.taxesInfo)
@@ -41,6 +51,8 @@ private extension OrderPaymentSection {
4151
static let orderTotal = NSLocalizedString("Order Total", comment: "Label for the the row showing the total cost of the order")
4252
static let taxesInfo = NSLocalizedString("Taxes will be automatically calculated based on your store settings.",
4353
comment: "Information about taxes and the order total when creating a new order")
54+
static let addShipping = NSLocalizedString("Add shipping", comment: "Title text of the button that adds shipping line when creating a new order")
55+
static let shippingTotal = NSLocalizedString("Shipping", comment: "Label for the row showing the cost of shipping in the order")
4456
}
4557
}
4658

0 commit comments

Comments
 (0)