diff --git a/Modules/Sources/Fakes/NetworkingCore.generated.swift b/Modules/Sources/Fakes/NetworkingCore.generated.swift index 2ae117583da..bd1e4bf76c9 100644 --- a/Modules/Sources/Fakes/NetworkingCore.generated.swift +++ b/Modules/Sources/Fakes/NetworkingCore.generated.swift @@ -185,7 +185,8 @@ extension NetworkingCore.Order { renewalSubscriptionID: .fake(), appliedGiftCards: .fake(), attributionInfo: .fake(), - shippingLabels: .fake() + shippingLabels: .fake(), + createdVia: .fake() ) } } diff --git a/Modules/Sources/NetworkingCore/Model/Copiable/Models+Copiable.generated.swift b/Modules/Sources/NetworkingCore/Model/Copiable/Models+Copiable.generated.swift index c19eb811619..e722a578015 100644 --- a/Modules/Sources/NetworkingCore/Model/Copiable/Models+Copiable.generated.swift +++ b/Modules/Sources/NetworkingCore/Model/Copiable/Models+Copiable.generated.swift @@ -239,7 +239,8 @@ extension NetworkingCore.Order { renewalSubscriptionID: NullableCopiableProp = .copy, appliedGiftCards: CopiableProp<[OrderGiftCard]> = .copy, attributionInfo: NullableCopiableProp = .copy, - shippingLabels: CopiableProp<[ShippingLabel]> = .copy + shippingLabels: CopiableProp<[ShippingLabel]> = .copy, + createdVia: NullableCopiableProp = .copy ) -> NetworkingCore.Order { let siteID = siteID ?? self.siteID let orderID = orderID ?? self.orderID @@ -280,6 +281,7 @@ extension NetworkingCore.Order { let appliedGiftCards = appliedGiftCards ?? self.appliedGiftCards let attributionInfo = attributionInfo ?? self.attributionInfo let shippingLabels = shippingLabels ?? self.shippingLabels + let createdVia = createdVia ?? self.createdVia return NetworkingCore.Order( siteID: siteID, @@ -320,7 +322,8 @@ extension NetworkingCore.Order { renewalSubscriptionID: renewalSubscriptionID, appliedGiftCards: appliedGiftCards, attributionInfo: attributionInfo, - shippingLabels: shippingLabels + shippingLabels: shippingLabels, + createdVia: createdVia ) } } diff --git a/Modules/Sources/NetworkingCore/Model/Order.swift b/Modules/Sources/NetworkingCore/Model/Order.swift index 89a3962f1d5..c774a7b2680 100644 --- a/Modules/Sources/NetworkingCore/Model/Order.swift +++ b/Modules/Sources/NetworkingCore/Model/Order.swift @@ -65,6 +65,10 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { /// public let shippingLabels: [ShippingLabel] + /// Set to orders created via specific sources (e.g. checkout, store-api, Point of Sale, ...) + /// + public let createdVia: String? + /// Order struct initializer. /// public init(siteID: Int64, @@ -105,7 +109,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { renewalSubscriptionID: String?, appliedGiftCards: [OrderGiftCard], attributionInfo: OrderAttributionInfo?, - shippingLabels: [ShippingLabel]) { + shippingLabels: [ShippingLabel], + createdVia: String?) { self.siteID = siteID self.orderID = orderID @@ -151,6 +156,7 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { self.appliedGiftCards = appliedGiftCards self.attributionInfo = attributionInfo self.shippingLabels = shippingLabels + self.createdVia = createdVia } @@ -187,7 +193,7 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { let paymentMethodID = try container.decode(String.self, forKey: .paymentMethodID) let paymentMethodTitle = try container.decode(String.self, forKey: .paymentMethodTitle) - // "payment_url" is only available on stores stores with version >= 6.4 + // "payment_url" is only available on stores with version >= 6.4 let paymentURL = try container.decodeIfPresent(URL.self, forKey: .paymentURL) let allOrderMetaData = try? container.decode([MetaData].self, forKey: .metadata) @@ -250,6 +256,9 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { /// It's fetched with a specific API request, while at the same time it has a relationship in Core Data with Order. let shippingLabels: [ShippingLabel] = [] + // "created_via" is only available on stores with version >= 9.9 + let createdVia = try container.decodeIfPresent(String.self, forKey: .createdVia) + self.init(siteID: siteID, orderID: orderID, parentID: parentID, @@ -288,7 +297,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { renewalSubscriptionID: renewalSubscriptionID, appliedGiftCards: appliedGiftCards, attributionInfo: attributionInfo, - shippingLabels: shippingLabels) + shippingLabels: shippingLabels, + createdVia: createdVia) } public static var empty: Order { @@ -330,7 +340,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable { renewalSubscriptionID: nil, appliedGiftCards: [], attributionInfo: nil, - shippingLabels: []) + shippingLabels: [], + createdVia: nil) } } diff --git a/Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift b/Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift index 48bce9a9723..71ae194044c 100644 --- a/Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift +++ b/Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift @@ -478,7 +478,7 @@ public extension OrdersRemote { "id", "parent_id", "number", "status", "currency", "currency_symbol", "customer_id", "customer_note", "date_created_gmt", "date_modified_gmt", "date_paid_gmt", "discount_total", "discount_tax", "shipping_total", "shipping_tax", "total", "total_tax", "payment_method", "payment_method_title", "payment_url", "line_items", "shipping", "billing", "coupon_lines", "shipping_lines", "refunds", "fee_lines", "order_key", "tax_lines", "meta_data", - "is_editable", "needs_payment", "needs_processing", "gift_cards" + "is_editable", "needs_payment", "needs_processing", "gift_cards", "created_via" ] static let dateModifiedField = "date_modified_gmt" } diff --git a/Modules/Sources/Yosemite/Model/Mocks/MockObjectGraph.swift b/Modules/Sources/Yosemite/Model/Mocks/MockObjectGraph.swift index ab2875fd576..d926198f217 100644 --- a/Modules/Sources/Yosemite/Model/Mocks/MockObjectGraph.swift +++ b/Modules/Sources/Yosemite/Model/Mocks/MockObjectGraph.swift @@ -386,7 +386,8 @@ extension MockObjectGraph { renewalSubscriptionID: nil, appliedGiftCards: [], attributionInfo: nil, - shippingLabels: [] + shippingLabels: [], + createdVia: "rest-api" ) } } diff --git a/Modules/Sources/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift b/Modules/Sources/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift index 7f1338eefde..3db40a014e2 100644 --- a/Modules/Sources/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift +++ b/Modules/Sources/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift @@ -66,6 +66,8 @@ extension Storage.Order: ReadOnlyConvertible { shippingPhone = shippingAddress.phone shippingEmail = shippingAddress.email } + + createdVia = order.createdVia } /// Returns a ReadOnly version of the receiver. @@ -119,7 +121,8 @@ extension Storage.Order: ReadOnlyConvertible { renewalSubscriptionID: renewalSubscriptionID, appliedGiftCards: orderGiftCards, attributionInfo: attributionInfo?.toReadOnly(), - shippingLabels: orderShippingLabels) + shippingLabels: orderShippingLabels, + createdVia: createdVia) } diff --git a/Modules/Sources/Yosemite/Stores/Order/OrderFactory.swift b/Modules/Sources/Yosemite/Stores/Order/OrderFactory.swift index 0c34ed87be4..b955ab5a268 100644 --- a/Modules/Sources/Yosemite/Stores/Order/OrderFactory.swift +++ b/Modules/Sources/Yosemite/Stores/Order/OrderFactory.swift @@ -47,7 +47,8 @@ public enum OrderFactory { renewalSubscriptionID: nil, appliedGiftCards: [], attributionInfo: nil, - shippingLabels: []) + shippingLabels: [], + createdVia: nil) } /// Creates a fee line suitable to be used within a simple payments order. diff --git a/Modules/Tests/NetworkingTests/Mapper/OrderMapperTests.swift b/Modules/Tests/NetworkingTests/Mapper/OrderMapperTests.swift index 9af60431730..13c630e67d0 100644 --- a/Modules/Tests/NetworkingTests/Mapper/OrderMapperTests.swift +++ b/Modules/Tests/NetworkingTests/Mapper/OrderMapperTests.swift @@ -43,6 +43,7 @@ final class OrderMapperTests: XCTestCase { XCTAssertEqual(order.total, "31.20") XCTAssertEqual(order.totalTax, "1.20") XCTAssertEqual(order.paymentURL, URL(string: "http://www.automattic.com")) + XCTAssertEqual(order.createdVia, "rest-api") } /// Verifies that all of the Order Fields are parsed correctly when response has no data envelope. @@ -75,6 +76,7 @@ final class OrderMapperTests: XCTestCase { XCTAssertEqual(order.total, "31.20") XCTAssertEqual(order.totalTax, "1.20") XCTAssertEqual(order.paymentURL, URL(string: "http://www.automattic.com")) + XCTAssertEqual(order.createdVia, "rest-api") } /// Verifies that all of the Order Address fields are parsed correctly. diff --git a/Modules/Tests/NetworkingTests/Responses/order-without-data.json b/Modules/Tests/NetworkingTests/Responses/order-without-data.json index d4b0283aebe..20832447b47 100644 --- a/Modules/Tests/NetworkingTests/Responses/order-without-data.json +++ b/Modules/Tests/NetworkingTests/Responses/order-without-data.json @@ -7,6 +7,7 @@ "number": "963", "status": "processing", "order_key": "abc123", + "created_via": "rest-api", "currency": "USD", "currency_symbol": "$", "date_created_gmt": "2018-04-03T23:05:12", diff --git a/Modules/Tests/NetworkingTests/Responses/order.json b/Modules/Tests/NetworkingTests/Responses/order.json index ee78abeb92c..f58b71e58c2 100644 --- a/Modules/Tests/NetworkingTests/Responses/order.json +++ b/Modules/Tests/NetworkingTests/Responses/order.json @@ -8,6 +8,7 @@ "number": "963", "status": "processing", "order_key": "abc123", + "created_via": "rest-api", "currency": "USD", "currency_symbol": "$", "date_created_gmt": "2018-04-03T23:05:12", diff --git a/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderListCellViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderListCellViewModel.swift index 526724b6047..e9c3df9b42e 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderListCellViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderListCellViewModel.swift @@ -78,9 +78,17 @@ struct OrderListCellViewModel { /// Textual representation of the sales channel /// - var salesChannel: String { - // Temporarily hardcoded. Will be handled on WOOMOB-661 - return "POS" + var salesChannel: String? { + guard let createdVia = order.createdVia else { + return nil + } + + switch createdVia { + case "pos-rest-api": + return "POS" + default: + return nil + } } /// The localized unabbreviated total for a given order item, which includes the currency. diff --git a/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderTableViewCell.swift b/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderTableViewCell.swift index abcb4774e3c..99f211917be 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderTableViewCell.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Cells/OrderTableViewCell.swift @@ -57,10 +57,11 @@ final class OrderTableViewCell: UITableViewCell & SearchResultCell { paymentStatusLabel.applyStyle(for: viewModel.status) paymentStatusLabel.text = viewModel.statusString - if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleOrdersi1) { + if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleOrdersi1), + let salesChannel = viewModel.salesChannel { salesChannelLabel.isHidden = false salesChannelLabel.applySalesChannelStyle() - salesChannelLabel.text = viewModel.salesChannel + salesChannelLabel.text = salesChannel } else { salesChannelLabel.isHidden = true } 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 d912159521d..d2987a454b4 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift @@ -515,7 +515,8 @@ struct EditAddressForm_Previews: PreviewProvider { renewalSubscriptionID: nil, appliedGiftCards: [], attributionInfo: nil, - shippingLabels: []) + shippingLabels: [], + createdVia: "rest-api") static let sampleAddress = Address(firstName: "Johnny", lastName: "Appleseed", diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift index 9ea468b73db..b8e030e3239 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackagesFormViewModel.swift @@ -489,7 +489,8 @@ extension ShippingLabelPackagesFormViewModel { renewalSubscriptionID: nil, appliedGiftCards: [], attributionInfo: nil, - shippingLabels: []) + shippingLabels: [], + createdVia: "rest-api") } static func sampleAddress() -> Address { diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift index 68f625dfbe5..ae0dc6e8917 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelSampleData.swift @@ -44,7 +44,8 @@ enum ShippingLabelSampleData { renewalSubscriptionID: nil, appliedGiftCards: [], attributionInfo: nil, - shippingLabels: []) + shippingLabels: [], + createdVia: nil) } static func samplePackageDetails() -> ShippingLabelPackagesResponse { diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift index ab431646783..e299c54e074 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/WooShippingPackageAndRatePlaceholder.swift @@ -74,43 +74,44 @@ import struct Yosemite.Order extension Order { static let sampleOrder = Order(siteID: 0, - orderID: 0, - parentID: 0, - customerID: 0, - orderKey: "1", - isEditable: false, - needsPayment: true, - needsProcessing: true, - number: "1", - status: .pending, - currency: "USD", - currencySymbol: "$", - customerNote: "note", - dateCreated: Date(), - dateModified: Date(), - datePaid: nil, - discountTotal: "", - discountTax: "", - shippingTotal: "", - shippingTax: "", - total: "1.00", - totalTax: "", - paymentMethodID: "stripe", - paymentMethodTitle: "Credit Card (Stripe)", - paymentURL: nil, - chargeID: nil, - items: [], - billingAddress: nil, - shippingAddress: nil, - shippingLines: [], - coupons: [], - refunds: [], - fees: [], - taxes: [], - customFields: [], - renewalSubscriptionID: nil, - appliedGiftCards: [], - attributionInfo: nil, - shippingLabels: []) + orderID: 0, + parentID: 0, + customerID: 0, + orderKey: "1", + isEditable: false, + needsPayment: true, + needsProcessing: true, + number: "1", + status: .pending, + currency: "USD", + currencySymbol: "$", + customerNote: "note", + dateCreated: Date(), + dateModified: Date(), + datePaid: nil, + discountTotal: "", + discountTax: "", + shippingTotal: "", + shippingTax: "", + total: "1.00", + totalTax: "", + paymentMethodID: "stripe", + paymentMethodTitle: "Credit Card (Stripe)", + paymentURL: nil, + chargeID: nil, + items: [], + billingAddress: nil, + shippingAddress: nil, + shippingLines: [], + coupons: [], + refunds: [], + fees: [], + taxes: [], + customFields: [], + renewalSubscriptionID: nil, + appliedGiftCards: [], + attributionInfo: nil, + shippingLabels: [], + createdVia: "rest-api") } #endif