Skip to content

Conversation

@jaclync
Copy link
Contributor

@jaclync jaclync commented Aug 26, 2025

For WOOMOB-1174

⚠️ Feel free to review only if the base PR #16041 doesn't require significant changes.

Description

This PR extends the POSCatalogSyncRemote implementation with basic catalog download functionality and returns the catalog of products and variations. Background download will be implemented separately in WOOMOB-1173.

Key Changes:

  • Implemented downloadCatalog() method with mapping from a full list of POSProduct to products and variations based on whether the product type is variation or not (the API response schema could change later, I'm keeping this mapping logic in the networking layer for now)
  • Created response model POSCatalog to contain arrays of products and variations
  • Added test coverage for the downloadCatalog endpoint including success scenarios, error handling, and edge cases. The success case uses a mock response with a simple product, variable product, and 2 associated variations

Steps to reproduce

Just CI passing is sufficient, as the remote isn't used in the app yet.

Testing information

I tested with

let catalogResponse = try await syncRemote.generateCatalog(for: siteID)
print("Job ID: \(catalogResponse.jobID)")
let jobID = catalogResponse.jobID
var isNotComplete = true
while isNotComplete {
    let statusResponse = try await syncRemote.checkCatalogStatus(for: siteID, jobID: jobID)
    if statusResponse.status == .complete {
        isNotComplete = false
        print("Job complete, download URL: \(statusResponse.downloadURL)")
        if let downloadURL = statusResponse.downloadURL {
            let catalog = try await syncRemote.downloadCatalog(for: siteID, downloadURL: downloadURL)
            print("Downloaded \(catalog.products.count) products and \(catalog.variations.count) variations for siteID \(siteID)\nProducts: \(catalog.products)\nVariations: \(catalog.variations)")
        }
    } else {
        print("Job status: \(statusResponse.status), progress \(statusResponse.progress), waiting 2 seconds...")
        try await Task.sleep(nanoseconds: 2_000_000_000)
    }
}

in the app to verify that the products & variations counts are as expected for the site.


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

@jaclync jaclync added this to the 23.2 milestone Aug 26, 2025
@jaclync jaclync changed the title [POS] Add downloadCatalog functionality and comprehensive test coverage [Local Catalog] Implement POS catalog download & parsing for full sync Aug 26, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Aug 26, 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 Numberpr16042-287a8ec
Version23.1
Bundle IDcom.automattic.alpha.woocommerce
Commit287a8ec
Installation URL37esonqh1v2a8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@joshheald joshheald self-assigned this Aug 26, 2025
Copy link
Contributor

@joshheald joshheald left a comment

Choose a reason for hiding this comment

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

Works well, thanks!

/// - downloadURL: Download URL of the catalog file.
/// - Returns: List of products and variations in the POS catalog.
public func downloadCatalog(for siteID: Int64, downloadURL: String) async throws -> POSCatalog {
// TODO: WOOMOB-1173 - move download task to the background using `URLSessionConfiguration.background`
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll have to change the function signature when we do this. I don't think it will be an async returning function any more. The app will get a callback when it's done, and have to handle the data there instead of here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, the background download could be tricky as we might need to handle related events from app delegate from this part of the documentation:

If your app is in the background, the system may suspend your app while the download is performed in another process. In this case, when the download finishes, the system resumes the app and calls the UIApplicationDelegate method application(_:handleEventsForBackgroundURLSession:completionHandler:). This method receives the session identifier you created in Creating a background URL session as its second parameter.

Going to start checking out the background download implementation today.

Base automatically changed from feat/WOOMOB-1170-full-sync-remote to trunk August 27, 2025 00:28
@jaclync jaclync merged commit 7e36659 into trunk Aug 27, 2025
15 checks passed
@jaclync jaclync deleted the feat/WOOMOB-1174-full-sync-catalog-download branch August 27, 2025 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants