Skip to content

[WOOMOB-3229] Cache edit and view context variation images separately#16272

Open
irfano wants to merge 11 commits into
issue/WOOMOB-3229-variation-image-removalfrom
issue/WOOMOB-3229-edit-context-image
Open

[WOOMOB-3229] Cache edit and view context variation images separately#16272
irfano wants to merge 11 commits into
issue/WOOMOB-3229-variation-image-removalfrom
issue/WOOMOB-3229-edit-context-image

Conversation

@irfano

@irfano irfano commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Description

This PR restores the variation images that #16245 unintentionally changed in the order creation picker and POS back to the trunk behavior, fixes the issues #16245 introduced, and fixes a variation image bug that exists on trunk.

WooCommerce renders a variation image in two contexts: edit context returns only the variation's own image, while view context returns the variation's own image, falling back to the parent product's image when the variation has none. #16245 switched the product screens to edit context but kept a single cached image, so the cache carried whichever context last wrote it. This PR stores the two values separately: image keeps the view value for the display surfaces, and the new editContextImage column keeps the variation's own image for the editing screens and the update request.

#16245 fixed the image removal, gave the editing screens their placeholder, and stopped the details screen from copying the image on save. This PR fixes what remained on that branch. In the examples below, a T-shirt product has a product image showing the white T-shirt, and its Blue variation has no image of its own, so the store shows the white T-shirt image for Blue.

  1. This issue also exists on trunk. Updating Blue's stock by scanning its barcode, or updating it through the AI assistant, silently set the white T-shirt image as Blue's own image on the server. From that point on Blue stopped following the product image: when the merchant later changed the product image, Blue kept the old white one. Updates now send the image only when it actually changed.
  2. Right after the merchant visited the variations screen, the order creation picker and POS listed Blue without any image until their next refresh. They now always show the white T-shirt image: these are view context screens, so a variation without its own image shows the parent product's image.
  3. Saving Blue from the details screen sent the right data to the server, but the screen then showed the white T-shirt image again as if it were Blue's own, until the next refresh. The editing screens now stay correct after a save.

Outside the product editing flows everything keeps fetching with view context and showing the same images as trunk. No POS code is touched in this PR.

Test Steps

Saving no longer copies the parent image onto the variation

  1. Create a variable product with a product image and a variation without its own image.
  2. In the app, go to Products.
  3. Open the variable product.
  4. Tap Variations.
  5. Open the variation.
  6. Change the regular price.
  7. Tap the update icon.
  8. Open the variation in web admin.
  9. Verify it still has no image of its own.

Placeholder on the editing screens

  1. Go to Products.
  2. Open the variable product.
  3. Tap Variations.
  4. Verify variations without their own image show a placeholder.
  5. Open one of them.
  6. Verify the details screen shows a placeholder.

Order creation picker keeps the product image after visiting the variations screen

Opening the variations screen first is what used to break the picker, so the first steps set that condition up.

  1. Go to Products.
  2. Open the variable product.
  3. Tap Variations.
  4. Go back.
  5. Go to Orders.
  6. Tap + to create an order.
  7. Tap Add products.
  8. Tap the variable product.
  9. Verify variations without their own image show the product image.

POS shows the product image as before

POS reads the view context image, so it looks the same as trunk even after the variations screen writes the edit data. The first steps set that condition up.

  1. Go to Products.
  2. Open the variable product.
  3. Tap Variations.
  4. Go back.
  5. Tap Point of Sale in the bottom bar.
  6. Tap the variable product.
  7. Verify variations without their own image show the product image.

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.

@irfano irfano added type: bug A confirmed bug. feature: variation details Related to adding or editing variations and attributes. labels Jul 16, 2026
@irfano irfano added this to the 25.3 milestone Jul 16, 2026
@dangermattic

dangermattic commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jul 16, 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
Commitc2b448f
Installation URL682nqs6kqnuqo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@irfano
irfano marked this pull request as ready for review July 16, 2026 20:56
@irfano
irfano requested a review from AdamGrzybkowski July 16, 2026 20:56

@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 - Found 2 potential issues

The core approach (splitting the variation's own image into editContextImage and keeping the display image separate, merging by fetch context) is sound and well tested. One issue below is in a file outside this PR's diff, so it is described here rather than inline.

[fix here] The variation detail screen still reads variation.image and will now show the wrong image. VariationDetailFragment.showVariationDetails() (lines 340 and 350, an unchanged file) still branches on variation.image to decide between the "Add image" placeholder and rendering the image. But the variation detail screen fetches with edit context (VariationDetailRepository.fetchVariation -> fetchSingleVariation(context = "edit")), and mergeEditContextResponse moves the response image into editContextImage while setting image to the stored display image (empty when none was previously fetched via view context). As a result, for a variation that has its own image, variation.image is null and the screen shows the "Add image" placeholder instead of the image; likewise a freshly uploaded image (now written to editContextImage, VariationDetailViewModel.kt:456) will not render. The list adapter and ViewModel were switched to editContextImage, but this Fragment was missed. Please update showVariationDetails() to use editContextImage.


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.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 18.29268% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.16%. Comparing base (dbde534) to head (7dd8aae).

Files with missing lines Patch % Lines
...rg/wordpress/android/fluxc/store/WCProductStore.kt 0.00% 33 Missing ⚠️
...erce/android/model/SubscriptionProductVariation.kt 0.00% 15 Missing ⚠️
.../com/woocommerce/android/model/ProductVariation.kt 31.57% 11 Missing and 2 partials ⚠️
...ui/products/variations/VariationDetailViewModel.kt 40.00% 2 Missing and 1 partial ⚠️
...rk/rest/wpcom/wc/product/ProductVariationMapper.kt 60.00% 1 Missing and 1 partial ⚠️
...ess/android/fluxc/model/WCProductVariationModel.kt 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                               Coverage Diff                               @@
##             issue/WOOMOB-3229-variation-image-removal   #16272      +/-   ##
===============================================================================
- Coverage                                        41.16%   41.16%   -0.01%     
- Complexity                                       13509    13522      +13     
===============================================================================
  Files                                             2503     2503              
  Lines                                           146464   146517      +53     
  Branches                                         21760    21773      +13     
===============================================================================
+ Hits                                             60295    60310      +15     
- Misses                                           80044    80085      +41     
+ Partials                                          6125     6122       -3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@irfano
irfano requested a review from samiuelson July 16, 2026 21:37
@irfano

irfano commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@samiuelson, can you please test the POS case in the test steps and confirm that the code changes don’t affect POS screens?

@samiuelson

Copy link
Copy Markdown
Contributor

@samiuelson, can you please test the POS case in the test steps and confirm that the code changes don’t affect POS screens?

Hi, @irfano, I verified POS displays variation images as expected 👍

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

Labels

feature: variation details Related to adding or editing variations and attributes. type: bug A confirmed bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants