Skip to content

Conversation

@itsmeichigo
Copy link
Contributor

@itsmeichigo itsmeichigo commented Apr 1, 2025

Closes: #15440

Description

This PR implements a few changes to support showing existing shipments on the split shipments screen:

  • Updated the order details screen to display the Create shipping label button even when a label is created. This is a temporary solution until [Order Details] Show create shipping label button if label not purchased for all items #15375 is done. This change is also hidden under the feature flag to ensure that the behavior of the legacy flow stays the same.
  • Updated the shipping label creation form to only load shipment configs and show the split shipments entry point if there are more than 1 item in the order.
  • Updated the split shipments screen to display existing shipments in the loaded configs.
  • Updated the shipment tabs when a shipment's label has already been purchased.
  • Disabled removing purchased shipments.
  • Updated the logic of merging all unfulfilled shipments to exclude purchased ones.

Note: the design found for the purchased shipment shows the checkbox disabled, but I think hiding the checkbox is simpler so I'm keeping that behavior.

Steps to reproduce

Testing the Create shipping label button on the order details screen

  1. Log in to a test store with Woo Shipping set up.
  2. On the web, open a complete order with more than 1 physical product with different quantities - split shipments and purchase the label for one of the shipments.
  3. Open the same order on the app and confirm that the Create shipping label button is available.
  4. Switch to a different store with only the legacy WCShip plugin set up.
  5. Open an order with a purchased shipping label and confirm that the Create shipping label button is unavailable.

Testing the split shipments entry point

  1. Log in to a test store with Woo Shipping set up.
  2. On the app, open a complete order with more than 1 physical product with different quantities.
  3. Select Create shipping label and confirm that the Split shipment entry point is displayed.
  4. Navigate back to the order list and select an order with only 1 physical product with 1 item.
  5. Select Create shipping label and confirm that the Split shipment entry point is not present.

Testing existing shipments

  1. Log in to a test store with Woo Shipping set up.
  2. On the web, open a complete order with more than 1 physical product with different quantities - split shipments and purchase the label for one of the shipments.
  3. Open the same order on the app and select Create shipping label > Split shipments.
  4. Confirm that the correct shipments are displayed.
  5. Confirm that the shipment with the purchased label is displayed with a check icon on the tab bar, and the items are not selectable.
  6. Tap the ellipsis button on the tab bar and confirm that the purchased shipment is not enabled as an option to remove.
  7. Select to remove any other shipments and confirm in the bottom sheet that the option to merge into the purchased shipment is disabled.
  8. Tap the ellipsis button again and select Merge all unfulfilled.
  9. Confirm that only unfulfilled shipments are merged.

Testing information

Tested and confirmed the above test cases in simulator iPhone 16 Pro iOS 18.2.

Screenshots

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-04-01.at.18.13.15.mp4

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

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

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

wpmobilebot commented Apr 1, 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 Number29125
VersionPR #15463
Bundle IDcom.automattic.alpha.woocommerce
Commit8a33bbb
Installation URL0vjnpdmo6gv5o
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@itsmeichigo itsmeichigo marked this pull request as ready for review April 1, 2025 11:22
@selanthiraiyan selanthiraiyan self-assigned this Apr 2, 2025
Comment on lines +107 to +109
let shipmentID = container.failsafeDecodeIfPresent(targetType: String.self,
forKey: .shipmentID,
alternativeTypes: [.integer(transform: { String($0) })])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While testing again I saw that the shipment ID was somehow returned as a number today. This is a workaround to transform the number to our expected string type.

Copy link
Contributor

@selanthiraiyan selanthiraiyan left a comment

Choose a reason for hiding this comment

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

The code looks great and the given test cases all passed. :shipit:


For an order with products with more than one quantities (with sub items), I noticed that after the shipments are saved from mobile the web isn't able to properly parse the saved information. i.e. The split shipments interface in web isn't working properly after the shipment is split from the mobile app.

SplitShipmentsInWeb.mov

This could be either an issue with how we save the shipments or how the web parses the shipments info. I think we should log a separate issue for this and investigate it.

I have logged an issue here. #15469

Comment on lines 28 to 43
if viewModel.currentShipment.isPurchased {
VStack {
Text(Localization.PurchasedShipment.title)
.bold()
.frame(maxWidth: .infinity, alignment: .leading)
Text(Localization.PurchasedShipment.subtitle)
.frame(maxWidth: .infinity, alignment: .leading)
}
.multilineTextAlignment(.leading)
.foregroundStyle(Layout.green)
.padding(Layout.contentPadding)
.background(
Layout.greenBackground
.clipShape(RoundedRectangle(cornerRadius: Layout.cornerRadius))
)
}
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: Consider moving this into a computed property to keep the main body less crowded. Perhaps named as shipmentPurchasedMessageView.

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 4e310d2.

Comment on lines +278 to +283
let totalOrderItems = order.items.map(\.quantity).reduce(0, +)
if totalOrderItems > 1 {
// Only fetch shipments info if there are more than one order items.
group.addTask {
await self.loadShipmentsInfo()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: We could move this totalOrderItems check logic into loadShipmentsInfo to keep the shipments-related logic inside one method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to remove this check when working on #15309, so I'll keep this for now.

Comment on lines 81 to 84
let purchasedIcon = UIImage(systemName: "checkmark.circle.fill")?.withRenderingMode(.alwaysTemplate)
return TopTabItem(name: String.localizedStringWithFormat(Localization.shipmentFormat, index + 1),
icon: item.isPurchased ? purchasedIcon : nil,
content: { EmptyView() })
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We could initialise the icon outside of the map to avoid creating the image for every shipment.

Suggested change
let purchasedIcon = UIImage(systemName: "checkmark.circle.fill")?.withRenderingMode(.alwaysTemplate)
return TopTabItem(name: String.localizedStringWithFormat(Localization.shipmentFormat, index + 1),
icon: item.isPurchased ? purchasedIcon : nil,
content: { EmptyView() })
let purchasedIcon = UIImage(systemName: "checkmark.circle.fill")?.withRenderingMode(.alwaysTemplate)
return shipments.enumerated().map { (index, item) in
TopTabItem(name: String.localizedStringWithFormat(Localization.shipmentFormat, index + 1),
icon: item.isPurchased ? purchasedIcon : nil,
content: { EmptyView() })
}

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 8a33bbb.

@itsmeichigo
Copy link
Contributor Author

Thank you @selanthiraiyan for the review!

For an order with products with more than one quantities (with sub items), I noticed that after the shipments are saved from mobile the web isn't able to properly parse the saved information. i.e. The split shipments interface in web isn't working properly after the shipment is split from the mobile app.

Good catch!

I have addressed the suggestions in subsequent commits, enabling auto-merge for now.

@itsmeichigo itsmeichigo enabled auto-merge April 2, 2025 05:33
@itsmeichigo itsmeichigo merged commit d8480d5 into trunk Apr 2, 2025
13 checks passed
@itsmeichigo itsmeichigo deleted the task/15440-purchased-shipment branch April 2, 2025 05:50
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.

[Split shipment] Disable selection for shipment with purchased label

4 participants