-
Notifications
You must be signed in to change notification settings - Fork 117
Shipping Labels: Migrate to the config endpoint for syncing shipping labels in Woo Shipping plugin #15800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shipping Labels: Migrate to the config endpoint for syncing shipping labels in Woo Shipping plugin #15800
Conversation
…oomob-646-migrate-to-config-endpoint-order-details
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few non blocking comments.
orderID: Int64, | ||
shippingLabels: [ShippingLabel], | ||
onCompletion: @escaping () -> Void) { | ||
guard shippingLabels.isEmpty == false else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super NIT: I'd replace the double negation by:
if shippingLabels.isEmpty {
return onCompletion()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 820fb02.
shippingLabels: [ShippingLabel], | ||
storageOrder: StorageOrder, | ||
using storage: StorageType) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIt: extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in 820fb02.
} | ||
} | ||
|
||
func update(shippingLabel storageShippingLabel: StorageShippingLabel, withRefund refund: ShippingLabelRefund?, using storage: StorageType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 820fb02.
@MainActor func syncShippingLabelsForWooShipping() async -> [ShippingLabel] { | ||
await withCheckedContinuation { continuation in | ||
stores.dispatch(WooShippingAction.syncShippingLabels(siteID: order.siteID, orderID: order.orderID) { result in | ||
switch result { | ||
case .success(let shippingLabels): | ||
ServiceLocator.analytics.track(event: .shippingLabelsAPIRequest( | ||
result: .success, | ||
isRevampedFlow: true | ||
)) | ||
continuation.resume(returning: shippingLabels) | ||
case .failure(let error): | ||
ServiceLocator.analytics.track(event: .shippingLabelsAPIRequest( | ||
result: .failed(error: error), | ||
isRevampedFlow: true | ||
)) | ||
if error as? DotcomError == .noRestRoute { | ||
DDLogError("⚠️ Endpoint for synchronizing shipping labels is unreachable. WC Shipping plugin may be missing.") | ||
} else { | ||
DDLogError("⛔️ Error synchronizing shipping labels: \(error)") | ||
} | ||
continuation.resume(returning: []) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
@MainActor func syncShippingLabelsForLegacyPlugin(isRevampedFlow: Bool) async -> [ShippingLabel] { | ||
await withCheckedContinuation { continuation in | ||
stores.dispatch(ShippingLabelAction.synchronizeShippingLabels(siteID: order.siteID, orderID: order.orderID) { result in | ||
switch result { | ||
case .success(let shippingLabels): | ||
ServiceLocator.analytics.track(event: .shippingLabelsAPIRequest( | ||
result: .success, | ||
isRevampedFlow: isRevampedFlow | ||
)) | ||
continuation.resume(returning: shippingLabels) | ||
case .failure(let error): | ||
ServiceLocator.analytics.track(event: .shippingLabelsAPIRequest( | ||
result: .failed(error: error), | ||
isRevampedFlow: isRevampedFlow | ||
)) | ||
if error as? DotcomError == .noRestRoute { | ||
DDLogError("⚠️ Endpoint for synchronizing shipping labels is unreachable. WC Shipping plugin may be missing.") | ||
} else { | ||
DDLogError("⛔️ Error synchronizing shipping labels: \(error)") | ||
} | ||
continuation.resume(returning: []) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The completion closure for ShippingLabelAction
and WooShippingAction
looks the same (despite isRevampedFlow
value, but I think it can be passed as attribute for both cases). I'd consider extracting and making it reusable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 370fcbe.
let title = { | ||
guard let shipmentID = shippingLabel.shipmentID, | ||
let intID = Int(shipmentID) else { | ||
return String.localizedStringWithFormat(Title.shippingLabelPackageFormat, index + 1) | ||
} | ||
return String.localizedStringWithFormat(Title.shippingLabelPackageFormat, intID + 1) | ||
}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also add a unit test to make sure that if a shippingLabel contains proper shipmentID
then shippingLabelSections
have proper titles as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test in 5301b3f.
order.shippingLabels.sorted(by: { label1, label2 in | ||
if let shipmentID1 = label1.shipmentID, | ||
let shipmentID2 = label2.shipmentID { | ||
return shipmentID1.localizedStandardCompare(shipmentID2) == .orderedAscending | ||
} | ||
return label1.dateCreated < label2.dateCreated | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a unit test to make sure that shippingLabels
are sorted basing on shipmentID
values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test added in 5301b3f should cover this already.
Closes WOOMOB-646
Description
This PR wraps up the migration for syncing shipping labels on the Order details screen. Detailed changes:
loadingConfig
, but it extracts the purchased shipping labels in the response and persists them in the storage.Testing steps
TC1: Regression check for a store with the legacy extension
GET wc/v1/connect/label
is triggered.TC2: Testing store with Woo Shipping
GET wcshipping/v1/config/label-purchase
is triggered.TC3: With feature flag disabled.
revampedShippingLabelCreation
and rebuild the app.GET wc/v1/connect/label
is triggered.Testing information
Tested and confirm the changes with simulator iPhone 16 iOS 18.4.
Screenshots
Simulator.Screen.Recording.-.iPhone.16.-.2025-06-24.at.13.36.38.mp4
RELEASE-NOTES.txt
if necessary.