diff --git a/Experiments/Experiments/DefaultFeatureFlagService.swift b/Experiments/Experiments/DefaultFeatureFlagService.swift index dce9c7739eb..964ec40a66f 100644 --- a/Experiments/Experiments/DefaultFeatureFlagService.swift +++ b/Experiments/Experiments/DefaultFeatureFlagService.swift @@ -33,8 +33,6 @@ public struct DefaultFeatureFlagService: FeatureFlagService { return true case .searchProductsBySKU: return true - case .orderCreationSearchCustomers: - return buildConfig == .localDeveloper || buildConfig == .alpha case .wpcomSignup: guard isFeatureFlagEnabled(.simplifiedLoginFlowI1) else { return buildConfig == .localDeveloper || buildConfig == .alpha diff --git a/Experiments/Experiments/FeatureFlag.swift b/Experiments/Experiments/FeatureFlag.swift index fac8751c95b..9edfa5c8b9d 100644 --- a/Experiments/Experiments/FeatureFlag.swift +++ b/Experiments/Experiments/FeatureFlag.swift @@ -70,10 +70,6 @@ public enum FeatureFlag: Int { /// case searchProductsBySKU - /// Enables the Search Customers functionality in the Order Creation screen - /// - case orderCreationSearchCustomers - /// Enables signing up for a WP.com account. /// case wpcomSignup diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 510b77135ff..6c81ef56981 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -2,7 +2,7 @@ 11.1 ----- - +- [**] You can now search customers when creating or editing an order. [https://github.com/woocommerce/woocommerce-ios/issues/7741] 11.0 ----- diff --git a/WooCommerce/Classes/Analytics/WooAnalyticsStat.swift b/WooCommerce/Classes/Analytics/WooAnalyticsStat.swift index 0c908376c5b..299b296219c 100644 --- a/WooCommerce/Classes/Analytics/WooAnalyticsStat.swift +++ b/WooCommerce/Classes/Analytics/WooAnalyticsStat.swift @@ -253,6 +253,8 @@ public enum WooAnalyticsStat: String { case orderCreateButtonTapped = "order_create_button_tapped" case orderCreationSuccess = "order_creation_success" case orderCreationFailed = "order_creation_failed" + case orderCreationCustomerAdded = "order_creation_customer_added" + case orderCreationCustomerSearch = "order_creation_customer_search" case orderContactAction = "order_contact_action" case orderCustomerAdd = "order_customer_add" case orderEditButtonTapped = "order_edit_button_tapped" diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift index eeed2279bd2..6abbdbde539 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift @@ -21,8 +21,13 @@ final class CustomerSearchUICommand: SearchUICommand { private let siteID: Int64 - init(siteID: Int64, onDidSelectSearchResult: @escaping ((Customer) -> Void)) { + private let analytics: Analytics + + init(siteID: Int64, + analytics: Analytics = ServiceLocator.analytics, + onDidSelectSearchResult: @escaping ((Customer) -> Void)) { self.siteID = siteID + self.analytics = analytics self.onDidSelectSearchResult = onDidSelectSearchResult } @@ -59,6 +64,7 @@ final class CustomerSearchUICommand: SearchUICommand { } func synchronizeModels(siteID: Int64, keyword: String, pageNumber: Int, pageSize: Int, onCompletion: ((Bool) -> Void)?) { + analytics.track(.orderCreationCustomerSearch) let action = CustomerAction.searchCustomers(siteID: siteID, keyword: keyword) { result in switch result { case .success(_): diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift index aa27e5d518c..9eecd943168 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift @@ -405,6 +405,7 @@ open class AddressFormViewModel: ObservableObject { /// Fills Order AddressFormFields with Customer details /// func customerSelectedFromSearch(customer: Customer) { + analytics.track(.orderCreationCustomerAdded) fillCustomerFields(customer: customer) let addressesDiffer = customer.billing != customer.shipping showDifferentAddressForm = addressesDiffer diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift index 51bf0069510..a9ea12b2b53 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift @@ -91,8 +91,6 @@ struct EditOrderAddressForm: View { @Environment(\.safeAreaInsets) var safeAreaInsets: EdgeInsets @State private var showingCustomerSearch: Bool = false - let isSearchCustomersEnabled = DefaultFeatureFlagService().isFeatureFlagEnabled(.orderCreationSearchCustomers) - var body: some View { Group { ScrollView { @@ -151,13 +149,11 @@ struct EditOrderAddressForm: View { }) } ToolbarItem(placement: .automatic) { - if isSearchCustomersEnabled { - Button(action: { - showingCustomerSearch = true - }, label: { - Image(systemName: "magnifyingglass") - }) - } + Button(action: { + showingCustomerSearch = true + }, label: { + Image(systemName: "magnifyingglass") + }) } ToolbarItem(placement: .confirmationAction) { navigationBarTrailingItem() diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift index 3947050db71..355f6b60a90 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift @@ -701,6 +701,25 @@ final class EditOrderAddressFormViewModelTests: XCTestCase { assertEqual(analyticsProvider.receivedProperties.first?["subject"] as? String, "billing_address") } + func test_view_model_when_customerSelectedFromSearch_then_tracks_orderCreationCustomerAdded() { + // Given + let analyticsProvider = MockAnalyticsProvider() + let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .billing, analytics: WooAnalytics(analyticsProvider: analyticsProvider)) + let customer = Customer.fake().copy( + email: "scrambled@scrambled.com", + firstName: "Johnny", + lastName: "Appleseed", + billing: sampleAddressWithEmptyNullableFields(), + shipping: sampleAddressWithEmptyNullableFields() + ) + + // When + viewModel.customerSelectedFromSearch(customer: customer) + + // Then + XCTAssert(analyticsProvider.receivedEvents.contains("order_creation_customer_added")) + } + func test_view_model_fires_error_notice_when_providing_an_invalid_email() { // Given let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .billing) diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift index 5281cc97c35..3a90767b9bf 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift @@ -4,6 +4,13 @@ import Yosemite final class CustomerSearchUICommandTests: XCTestCase { private let sampleSiteID: Int64 = 123 + private var analyticsProvider: MockAnalyticsProvider! + private var analytics: Analytics! + + override func setUp() { + analyticsProvider = MockAnalyticsProvider() + analytics = WooAnalytics(analyticsProvider: analyticsProvider) + } func test_searchResultsPredicate_includes_siteID_and_keyword_when_keyword() { // Given @@ -35,4 +42,23 @@ final class CustomerSearchUICommandTests: XCTestCase { XCTAssertEqual(cellViewModel.title, "\(customer.firstName ?? "") \(customer.lastName ?? "")") XCTAssertEqual(cellViewModel.subtitle, String(customer.email)) } + + func test_CustomerSearchUICommand_when_synchronizeModels_then_tracks_orderCreationCustomerSearch_event() { + // Given + let command = CustomerSearchUICommand( + siteID: sampleSiteID, + analytics: analytics) { _ in } + + // When + command.synchronizeModels( + siteID: sampleSiteID, + keyword: "", + pageNumber: 1, + pageSize: 1, + onCompletion: { _ in } + ) + + // Then + XCTAssert(analyticsProvider.receivedEvents.contains("order_creation_customer_search")) + } }