woocommerce-android icon indicating copy to clipboard operation
woocommerce-android copied to clipboard

[Bug] Adding item by scanner fails if DB is not synced

Open samiuelson opened this issue 1 year ago • 2 comments

Closes: #11379

Description

A user has reported that they are not able to add variation to the order by scanning a barcode. Context: peaMlT-B1-p2

It appears that the root problem was related to the situation when the variation is not stored in the local db, e.g. after a fresh app install. Unlike the case when the item is selected manually from the product selector, the code that was looking for the product based on the barcode (SKU) was querying only the local DB.

The solution was to migrate to fetchProductOrLoadFromCache function that fetches the product from the backend in case it's not found in the local storage.

Testing instructions

  1. Clear app's storage
  2. Scan the barcode of a variation
  3. Verify it's added to the order correctly
  • [x] 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.

samiuelson avatar Apr 26 '24 11:04 samiuelson

📲 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
Commit7a80a71a6285cb97ae474c1aeb481a0dce8af39f
Direct Downloadwoocommerce-prototype-build-pr11386-7a80a71.apk

wpmobilebot avatar Apr 26 '24 11:04 wpmobilebot

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 41.15%. Comparing base (40f5314) to head (7a80a71). Report is 129 commits behind head on trunk.

Files Patch % Lines
...erce/android/ui/orders/creation/CreateOrderItem.kt 0.00% 2 Missing :warning:
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #11386   +/-   ##
=========================================
  Coverage     41.15%   41.15%           
  Complexity     5218     5218           
=========================================
  Files          1062     1062           
  Lines         62279    62279           
  Branches       8495     8495           
=========================================
  Hits          25634    25634           
  Misses        34342    34342           
  Partials       2303     2303           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Apr 26 '24 11:04 codecov-commenter

Hey @samiuelson was AFK when this was assigned. Started the review process!

jd-alexander avatar Apr 30 '24 02:04 jd-alexander

Hey @samiuelson good work on this feature. I am having an error and I am wondering if it could be my product setup. So when I scan the barcode of a specific variation, I get the main product and not the product variation. I only get the right variation if I manually go in and and a variation of a product and then do a barcode scan afterwards. I am going to give this another test but just sharing initial thoughts.

jd-alexander avatar Apr 30 '24 14:04 jd-alexander

1 Warning
:warning: This PR is assigned to the milestone 18.5. 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 :no_entry_sign: Danger

dangermattic avatar May 01 '24 13:05 dangermattic

Hey @samiuelson good work on this feature. I am having an error and I am wondering if it could be my product setup. So when I scan the barcode of a specific variation, I get the main product and not the product variation. I only get the right variation if I manually go in and and a variation of a product and then do a barcode scan afterwards. I am going to give this another test but just sharing initial thoughts.

👋🏼 Thanks for review, @jd-alexander. I've fixed this with https://github.com/woocommerce/woocommerce-android/pull/11386/commits/7a80a71a6285cb97ae474c1aeb481a0dce8af39f.

It turned out that the function retrieving the variation was fetching it from the local DB only as well (variationDetailRepository.getVariation). Using variationDetailRepository.getVariationOrNull solves the problem because it fetches the variation from the backend in case it's not present in the DB.

samiuelson avatar May 01 '24 13:05 samiuelson