Skip to content

[WOOMOB-3586] Use WooCommerce's product duplication endpoint#16262

Open
hichamboushaba wants to merge 3 commits into
trunkfrom
issue/woomob-3586-server-product-duplication
Open

[WOOMOB-3586] Use WooCommerce's product duplication endpoint#16262
hichamboushaba wants to merge 3 commits into
trunkfrom
issue/woomob-3586-server-product-duplication

Conversation

@hichamboushaba

@hichamboushaba hichamboushaba commented Jul 14, 2026

Copy link
Copy Markdown
Member

Description

Fixes WOOMOB-3586

Android now calls WooCommerce Core's server-side product duplicate endpoint so duplicated products preserve the data managed by WooCommerce. The existing client-side implementation remains as a compatibility fallback only when the endpoint is conclusively absent: the error must be API_NOT_FOUND with the rest_no_route API code.

Other or ambiguous errors remain terminal. Product duplication is non-idempotent, so retrying with the local implementation after an uncertain server response could create two products.

The network response intentionally maps only the duplicated product ID. WooCommerce Core returns raw product data from this endpoint rather than the canonical REST product representation, and the destination product screen performs the normal canonical fetch and cache flow.

ProductDetailRepository exposes the operation as Kotlin Result<Long>. The existing progress dialog, destination navigation, and analytics behavior remain unchanged.

Test Steps

  1. On a WooCommerce 8.9+ test store, choose a benign product with images, a description, a price, inventory, shipping details, and a category.
  2. Open Products, open the product detail screen, then select the overflow menu > Duplicate.
  3. Verify the progress dialog appears, the app navigates to a distinct Draft whose name uses the server-style (Copy) suffix, and all of the listed product fields load.
  4. Return to the source product and verify it is unchanged and no second duplicate was created.
  5. To verify the compatibility fallback, configure ApiFaker with exactly one WP API endpoint matching POST /wc/v3/products/<source-id>/duplicate, status 404, and this response body:
    {"code":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}
  6. Enable ApiFaker and duplicate the source once. Verify logcat shows the exact /duplicate endpoint match followed by one legacy ADD_PRODUCT request, the app opens one new Draft, and no second duplicate is created.
  7. Clear the ApiFaker endpoint, then configure the same request with status 404 and this non-route response body:
    {"code":"woocommerce_rest_product_invalid_id","message":"Invalid product ID.","data":{"status":404}}
  8. Duplicate the source once. Verify the app shows “Cannot duplicate product,” remains on the source product, creates no Draft, and logcat contains no ADD_PRODUCT request.

Images/gif

N/A

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@hichamboushaba hichamboushaba added type: enhancement A request for an enhancement. feature: product details Related to adding or editing products, includes product settings. category: unit tests Related to unit testing. labels Jul 14, 2026
@hichamboushaba hichamboushaba added this to the 25.3 milestone Jul 14, 2026
@wpmobilebot

wpmobilebot commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

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

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Build Number772
Version25.2-rc-1
Application IDcom.woocommerce.android.prealpha
Commit18012d1
Installation URL7pfag4gl410sg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@hichamboushaba hichamboushaba changed the title [WOOMOB-3586] Preserve product data when duplicating products [WOOMOB-3586] Use WooCommerce's product duplication endpoint Jul 15, 2026
@hichamboushaba
hichamboushaba force-pushed the issue/woomob-3586-server-product-duplication branch from 3c52976 to 18012d1 Compare July 15, 2026 09:56
@hichamboushaba
hichamboushaba marked this pull request as ready for review July 15, 2026 10:55

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI Code Review - No issues found. The changes look good.

The PR adds server-side product duplication (POST /wc/v3/products/<id>/duplicate) with a safe fallback to the existing client-side flow when the route is missing on older stores. The layering (REST client -> store -> repository -> use case) is clean, error/edge cases (missing/zero/negative IDs, non-route errors) are guarded, and the change is well covered by unit tests at every layer. I traced the endpoint path generation and confirmed the trailing slash is normalized by EndpointTreeGenerator, so the generated pathV3 matches the asserted /wc/v3/products/123/duplicate/.

PR housekeeping
  • Nit: in wc-wp-api-endpoints.txt the new /products/<id>/duplicate entry omits the trailing slash that its neighbours use (availability/, variations/). Functionally irrelevant (the processor normalizes it), but adding the slash keeps the file consistent.
  • Applied repo AGENTS.md/CLAUDE.md guidance while reviewing (Store Management data-layer patterns, FluxC store/repository conventions).

Automatic review · claude-opus-4-8 · Workflow run

How to reply to a finding

Reply on this review (or inline at the line the finding refers to) with one of:

  • @claude addressed - I made the change. Bot verifies against the next diff before marking resolved.
  • @claude rejected: <reason> - Will not fix; reason gets quoted on the next review.
  • @claude not-applicable - Finding does not apply (wrong file, already covered elsewhere, etc.).

The bot honours these on the next review pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: unit tests Related to unit testing. feature: product details Related to adding or editing products, includes product settings. type: enhancement A request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants