Skip to content

Conversation

@samiuelson
Copy link
Contributor

@samiuelson samiuelson commented Sep 19, 2025

WOOMOB-1072

Description

The goal of this PR is to load products from the DB instead of the existing in-memory cache / remote call hybrid store. Currently, the logic that decides on which data source to use is based on the feature flag WOO_POS_LOCAL_CATALOG_M1 state.

⚠️ Known issue: WOOMOB-1370 - variations have wrong names. This will be solved in a separate PR.

Steps to reproduce

Testing information

  1. Verify that in the release build (FF disabled), the previous data source implementation is used.
  2. Verify that PTR works when FF is disabled.
  3. When the FF is enabled, verify that products load correctly - full list. They should load significantly faster without pagination.

The tests that have been performed

Above

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.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 19, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit0f3456a
Direct Downloadwoocommerce-wear-prototype-build-pr14636-0f3456a.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 19, 2025

📲 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
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit0f3456a
Direct Downloadwoocommerce-prototype-build-pr14636-0f3456a.apk

@samiuelson samiuelson changed the base branch from trunk to woomob-1069-woo-poslocal-catalog-update-ptr-behavior-fetch-products-and September 19, 2025 12:18
…tch-products-and' into woomob-1072-woo-poslocal-catalog-connect-product-list-to-pos-products
@samiuelson samiuelson added this to the 23.4 milestone Sep 19, 2025
@samiuelson samiuelson added feature: point of sale POS project type: task An internally driven task. labels Sep 19, 2025
@samiuelson samiuelson requested a review from Copilot September 19, 2025 12:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR integrates local database storage for the POS product catalog, controlled by the WOO_POS_LOCAL_CATALOG_M1 feature flag. When enabled, products are loaded from the local database instead of the existing cache/remote hybrid approach.

  • Adds sorting by product name (case-insensitive) at the database level
  • Introduces a new database-backed data source for products with search filtering capabilities
  • Updates product retrieval logic in cart and totals repositories to support both local catalog and legacy flows

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
WooPosProductsDao.kt Adds case-insensitive sorting by name to database query
WooPosProductsInDbDataSource.kt New data source implementation for database-backed product loading
WooPosProductsDataSourceInterface.kt Interface to unify different product data source implementations
WooPosProductsViewModel.kt Updates to use feature flag-based data source selection
WooPosTotalsRepository.kt Adds conditional product retrieval from local catalog
WooPosCartViewModel.kt Adds conditional product retrieval from local catalog
Test files Updates and new tests to support the changes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 44.82759% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.42%. Comparing base (105f3a4) to head (0f3456a).
⚠️ Report is 29 commits behind head on trunk.

Files with missing lines Patch % Lines
...id/ui/woopos/common/data/WooPosGetVariationById.kt 0.00% 15 Missing ⚠️
...pos/home/items/products/WooPosProductsViewModel.kt 50.00% 3 Missing and 2 partials ⚠️
...android/ui/woopos/home/cart/WooPosCartViewModel.kt 0.00% 0 Missing and 3 partials ⚠️
...os/home/items/products/WooPosProductsDataSource.kt 50.00% 3 Missing ⚠️
...id/ui/woopos/home/totals/WooPosTotalsRepository.kt 0.00% 2 Missing and 1 partial ⚠️
...ome/items/products/WooPosProductsInDbDataSource.kt 87.50% 1 Missing and 1 partial ⚠️
...home/items/variations/WooPosVariationsViewModel.kt 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #14636   +/-   ##
=========================================
  Coverage     38.42%   38.42%           
- Complexity     9812     9818    +6     
=========================================
  Files          2086     2087    +1     
  Lines        116448   116470   +22     
  Branches      15563    15563           
=========================================
+ Hits          44748    44757    +9     
- Misses        67549    67562   +13     
  Partials       4151     4151           

☔ View full report in Codecov by Sentry.
📢 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.

@samiuelson samiuelson marked this pull request as ready for review September 19, 2025 14:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@samiuelson samiuelson requested review from kidinov and removed request for malinajirka September 29, 2025 15:45
@kidinov kidinov self-assigned this Sep 30, 2025

init {
listenEventsFromParent()
viewModelScope.launch {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this or should the data source object be created every time when the VM is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not needed since fetchFirstPage() already handles the state reset internally. Removed: 0f3456a

private suspend fun handleSimpleProductClicked(productId: Long): WooPosCartItemViewState {
val product = getProductById(productId)!!
val product = when {
wooPosLocalCatalogM1Enabled() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'll be better to have this logic in WooPosGetProductById as this reusable component that used in many places. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good idea. Done in b1e60e4

private suspend fun handleVariationClicked(productId: Long, variationId: Long): WooPosCartItemViewState {
val product = getProductById(productId)!!
val product = when {
wooPosLocalCatalogM1Enabled() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Even in this VM you have the same code twice, so imo should be in getProductById

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored in b1e60e4

else -> getProductById(itemData.productId)!!
}
val variationResult = when {
wooPosLocalCatalogM1Enabled() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for getVariationById

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 b1e60e4

private val resourceProvider: ResourceProvider,
) : ViewModel() {

private val currentDataSource: WooPosProductsDataSourceInterface = when (wooPosLocalCatalogM1Enabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered moving this to the place where the instance is created, e.g. in dagger module? So the right implementation will be injected everywhere where needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Moved this to the module: 57b2078

Copy link
Contributor

@kidinov kidinov left a comment

Choose a reason for hiding this comment

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

LGTM! I left a couple of comments, please take a look!

Base automatically changed from woomob-1069-woo-poslocal-catalog-update-ptr-behavior-fetch-products-and to trunk September 30, 2025 13:53
@samiuelson samiuelson merged commit e86309e into trunk Sep 30, 2025
15 checks passed
@samiuelson samiuelson deleted the woomob-1072-woo-poslocal-catalog-connect-product-list-to-pos-products branch September 30, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: point of sale POS project type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants