Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Modules/Sources/Fakes/NetworkingCore.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ extension NetworkingCore.Order {
renewalSubscriptionID: .fake(),
appliedGiftCards: .fake(),
attributionInfo: .fake(),
shippingLabels: .fake()
shippingLabels: .fake(),
createdVia: .fake()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ extension NetworkingCore.Order {
renewalSubscriptionID: NullableCopiableProp<String> = .copy,
appliedGiftCards: CopiableProp<[OrderGiftCard]> = .copy,
attributionInfo: NullableCopiableProp<OrderAttributionInfo> = .copy,
shippingLabels: CopiableProp<[ShippingLabel]> = .copy
shippingLabels: CopiableProp<[ShippingLabel]> = .copy,
createdVia: NullableCopiableProp<String> = .copy
) -> NetworkingCore.Order {
let siteID = siteID ?? self.siteID
let orderID = orderID ?? self.orderID
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -320,7 +322,8 @@ extension NetworkingCore.Order {
renewalSubscriptionID: renewalSubscriptionID,
appliedGiftCards: appliedGiftCards,
attributionInfo: attributionInfo,
shippingLabels: shippingLabels
shippingLabels: shippingLabels,
createdVia: createdVia
)
}
}
Expand Down
19 changes: 15 additions & 4 deletions Modules/Sources/NetworkingCore/Model/Order.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -151,6 +156,7 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
self.appliedGiftCards = appliedGiftCards
self.attributionInfo = attributionInfo
self.shippingLabels = shippingLabels
self.createdVia = createdVia
}


Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️

let paymentURL = try container.decodeIfPresent(URL.self, forKey: .paymentURL)

let allOrderMetaData = try? container.decode([MetaData].self, forKey: .metadata)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -330,7 +340,8 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
renewalSubscriptionID: nil,
appliedGiftCards: [],
attributionInfo: nil,
shippingLabels: [])
shippingLabels: [],
createdVia: nil)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/Sources/NetworkingCore/Remote/OrdersRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/Sources/Yosemite/Model/Mocks/MockObjectGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ extension MockObjectGraph {
renewalSubscriptionID: nil,
appliedGiftCards: [],
attributionInfo: nil,
shippingLabels: []
shippingLabels: [],
createdVia: "rest-api"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ extension Storage.Order: ReadOnlyConvertible {
shippingPhone = shippingAddress.phone
shippingEmail = shippingAddress.email
}

createdVia = order.createdVia
}

/// Returns a ReadOnly version of the receiver.
Expand Down Expand Up @@ -119,7 +121,8 @@ extension Storage.Order: ReadOnlyConvertible {
renewalSubscriptionID: renewalSubscriptionID,
appliedGiftCards: orderGiftCards,
attributionInfo: attributionInfo?.toReadOnly(),
shippingLabels: orderShippingLabels)
shippingLabels: orderShippingLabels,
createdVia: createdVia)

}

Expand Down
3 changes: 2 additions & 1 deletion Modules/Sources/Yosemite/Stores/Order/OrderFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Modules/Tests/NetworkingTests/Mapper/OrderMapperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Modules/Tests/NetworkingTests/Responses/order.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Comment on lines +81 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the sales channel implementation detail could live in Yosemite, like an extension of Order, so that the app layer doesn't have to know about this "created_via" property and the sales channel can be reused for other order use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense 🤔 , I'll go ahead and merge this one for now, then take a spin to your suggestion in #15848

}

/// The localized unabbreviated total for a given order item, which includes the currency.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ extension ShippingLabelPackagesFormViewModel {
renewalSubscriptionID: nil,
appliedGiftCards: [],
attributionInfo: nil,
shippingLabels: [])
shippingLabels: [],
createdVia: "rest-api")
}

static func sampleAddress() -> Address {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ enum ShippingLabelSampleData {
renewalSubscriptionID: nil,
appliedGiftCards: [],
attributionInfo: nil,
shippingLabels: [])
shippingLabels: [],
createdVia: nil)
}

static func samplePackageDetails() -> ShippingLabelPackagesResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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