Skip to content

Handle fetching variations when duplicating variable products#10235

Merged
0nko merged 3 commits intotrunkfrom
issue/10232-fix-variable-product-duplication
Nov 23, 2023
Merged

Handle fetching variations when duplicating variable products#10235
0nko merged 3 commits intotrunkfrom
issue/10232-fix-variable-product-duplication

Conversation

@hichamboushaba
Copy link
Copy Markdown
Member

@hichamboushaba hichamboushaba commented Nov 23, 2023

Closes: #10232

Description

Currently, when trying to duplicate a variable product, we use try to duplicate just the list of cached variations, which causes two issues:

  1. The request fails when we try to duplicate a product for which we didn't fetch the variations yet.
  2. We might use outdated data when the cached data is not up-to-date.

This PR adds logic to actually fetch variations before proceeding to duplicating them.

Testing instructions

  1. Create a variable product and some variations in wp-admin.
  2. Open the product in the app.
  3. Click on Duplicate.
  4. Confirm the duplication works correctly, and the variations have correct data.

Repeat also for a variable subscription.

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

@hichamboushaba hichamboushaba added type: bug A confirmed bug. feature: product details Related to adding or editing products, includes product settings. labels Nov 23, 2023
@hichamboushaba hichamboushaba added this to the 16.4 milestone Nov 23, 2023
Comment on lines +62 to +68
if (it.size > 100) {
// The API doesn't allow to create more than 100 variations at once
WooLog.w(
WooLog.T.PRODUCTS, "Variations list is too big: ${it.size}, " +
"the duplicate will have only the first 100 variations"
)
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The endpoint we use for the variations creation can handle only 100 items (https://woocommerce.github.io/woocommerce-rest-api-docs/#batch-update-product-variations), while we can make multiple calls to handle the creation in this case, I think it's not worth it, as this should be a very rare case, WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree.

@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented Nov 23, 2023

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

App Name WooCommerce Android
FlavorJalapeno
Build TypeDebug
Commit7a7549b
Direct Downloadwoocommerce-prototype-build-pr10235-7a7549b.apk

@hichamboushaba hichamboushaba marked this pull request as ready for review November 23, 2023 12:13
@wpmobilebot
Copy link
Copy Markdown
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 16.4. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (ea716f6) 42.31% compared to head (7a7549b) 42.31%.
Report is 39 commits behind head on trunk.

Files Patch % Lines
...oocommerce/android/ui/products/DuplicateProduct.kt 61.53% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #10235   +/-   ##
=========================================
  Coverage     42.31%   42.31%           
  Complexity     4803     4803           
=========================================
  Files           977      977           
  Lines         54282    54293   +11     
  Branches       7170     7172    +2     
=========================================
+ Hits          22969    22975    +6     
- Misses        29306    29309    +3     
- Partials       2007     2009    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@0nko 0nko self-assigned this Nov 23, 2023
Copy link
Copy Markdown
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

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

:shipit:

@0nko 0nko merged commit a1f3ef1 into trunk Nov 23, 2023
@0nko 0nko deleted the issue/10232-fix-variable-product-duplication branch November 23, 2023 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: product details Related to adding or editing products, includes product settings. type: bug A confirmed bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicating variable products doesn't work well

4 participants