Skip to content

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

Merged
merged 14 commits into from
Jun 25, 2025

Conversation

itsmeichigo
Copy link
Contributor

@itsmeichigo itsmeichigo commented Jun 23, 2025

Closes WOOMOB-646

Description

This PR wraps up the migration for syncing shipping labels on the Order details screen. Detailed changes:

  • Updates WooShippingAction and WooShippingStore with a new method to sync shipping labels. This uses the same config endpoint underneath like loadingConfig, but it extracts the purchased shipping labels in the response and persists them in the storage.
  • Updates the order details screen:
    • Checks for the feature flag and whether the store has Woo Shipping extension installed. If yes, use the new syncing method in WooShippingAction. Otherwise, fall back to the legacy method in ShippingLabelAction.
    • Sorts the fetched shipping labels by either shipment ID if available or created date. This fixes the issue with the labels jumping in positions after syncing.
    • Updates the section title for purchased labels based on shipment IDs if available and fall back to their index otherwise.
    • Updates unit tests to confirm logic changes.

Testing steps

TC1: Regression check for a store with the legacy extension

  1. Log in to a test store with the Woo Tax plugin without the Woo Shipping (deactivate it if you have it installed). Use the smoke testing store [P91TBi-bVe-p2] if you don't already have a store that you used to create shipping labels with this extension.
  2. Navigate to an order with physical products.
  3. Confirm that the legacy endpoint GET wc/v1/connect/label is triggered.
  4. Create a shipping label for the order - ensure to split items into multiple packages.
  5. Navigate back to the order details and confirm that purchased labels are displayed with package indices in ASC orders.
  6. Navigate back and forth from the order details screen and confirm that the position of the purchased label sections is not changed.

TC2: Testing store with Woo Shipping

  1. Log in to a test store with the Woo Shipping plugin set up.
  2. Navigate to a paid order with physical products.
  3. Confirm that the new endpoint GET wcshipping/v1/config/label-purchase is triggered.
  4. Select Create shipping label button and proceed to split items into multiple shipments and purchase labels for all of them.
  5. Navigate back to the order details and confirm that purchased labels are displayed with package indices in ASC orders.
  6. Select View purchased label and confirm that the correct shipment is displayed. The index of the shipment should match the selected package's.
  7. Navigate back and forth from the order details screen and confirm that the position of the purchased label sections is not changed.

TC3: With feature flag disabled.

  1. Disable the feature flag revampedShippingLabelCreation and rebuild the app.
  2. Log in to the same store and select the same order in TC2.
  3. Confirm that the legacy endpoint GET wc/v1/connect/label is triggered.
  4. Confirm that purchased labels are displayed with package indices in ASC orders.
  5. Navigate back and forth from the order details screen and confirm that the position of the purchased label sections is not changed.

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

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@itsmeichigo itsmeichigo added this to the 22.7 milestone Jun 23, 2025
@itsmeichigo itsmeichigo added type: task An internally driven task. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Jun 23, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jun 23, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Number30708
VersionPR #15800
Bundle IDcom.automattic.alpha.woocommerce
Commit5301b3f
Installation URL1c20p05cmcnc0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Base automatically changed from woomob-646-parse-shipmentID-for-shipping-labels to trunk June 24, 2025 02:53
@itsmeichigo itsmeichigo marked this pull request as ready for review June 24, 2025 06:41
Copy link
Contributor

@RafaelKayumov RafaelKayumov left a 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 {
Copy link
Contributor

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()
}

Copy link
Contributor Author

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) {

Copy link
Contributor

Choose a reason for hiding this comment

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

NIt: extra line

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 820fb02.

Comment on lines 953 to 1003
@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: [])
}
})
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 370fcbe.

Comment on lines +1310 to +1316
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)
}()
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added test in 5301b3f.

Comment on lines +111 to +117
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
})
Copy link
Contributor

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

Copy link
Contributor Author

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.

@itsmeichigo itsmeichigo merged commit 895f41e into trunk Jun 25, 2025
13 checks passed
@itsmeichigo itsmeichigo deleted the woomob-646-migrate-to-config-endpoint-order-details branch June 25, 2025 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: shipping labels Related to creating, ordering, or printing shipping labels. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants