Skip to content

Commit 2346e2d

Browse files
committed
Tracks order status change]
1 parent d23c60b commit 2346e2d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ final class NewOrderViewModel: ObservableObject {
232232
/// Assign this closure to be notified when a new order is created
233233
///
234234
var onOrderCreated: (Order) -> Void = { _ in }
235+
236+
/// Updates the order status & tracks its event
237+
///
238+
func updateOrderStatus(newStatus: OrderStatusEnum) {
239+
let oldStatus = orderDetails.status
240+
orderDetails.status = newStatus
241+
analytics.track(event: WooAnalyticsEvent.Orders.orderStatusChange(flow: .creation, from: oldStatus, to: newStatus))
242+
}
235243
}
236244

237245
// MARK: - Types
@@ -501,7 +509,8 @@ private extension NewOrderViewModel {
501509
/// Tracks when the create order button is tapped.
502510
///
503511
/// Warning: This methods assume that `orderDetails.items.count` is equal to the product count,
504-
/// As the module evolves to handle more types of items we should update this property to something like `itemsCount` or figure a better way to get the product count.
512+
/// As the module evolves to handle more types of items, we need to update the property to something like `itemsCount`
513+
/// or figure out a better way to get the product count.
505514
///
506515
func trackCreateButtonTapped() {
507516
let hasCustomerDetails = orderDetails.billingAddress != nil || orderDetails.shippingAddress != nil

WooCommerce/Classes/ViewRelated/Orders/Order Creation/StatusSection/OrderStatusSection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct OrderStatusSection: View {
3434
.padding(.trailing, -Layout.linkButtonTrailingPadding) // remove trailing padding to align button title to the side
3535
.sheet(isPresented: $viewModel.shouldShowOrderStatusList) {
3636
OrderStatusList(siteID: viewModel.siteID, status: viewModel.orderDetails.status) { newStatus in
37-
viewModel.orderDetails.status = newStatus
37+
viewModel.updateOrderStatus(newStatus: newStatus)
3838
}
3939
}
4040
}

0 commit comments

Comments
 (0)