-
Notifications
You must be signed in to change notification settings - Fork 136
Increment product quantity when the same product is scanned more than one time #9083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ct is scanned more than once.
…en same product is scanned more than once.
…ue/9081-increment-product-quantity # Conflicts: # WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/creation/CreationFocusedOrderCreateEditViewModelTest.kt
|
You can test the changes on this Pull Request by downloading an installable build, or scanning this QR code: |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## issue/9073-handle-error-case-barcode-scanning #9083 +/- ##
===================================================================================
- Coverage 43.59% 43.54% -0.06%
+ Complexity 4094 4041 -53
===================================================================================
Files 834 833 -1
Lines 43985 43941 -44
Branches 5763 5741 -22
===================================================================================
- Hits 19176 19133 -43
+ Misses 23137 23134 -3
- Partials 1672 1674 +2
☔ View full report in Codecov by Sentry. |
…sponse from the product search using SKU returns type as "variation" for variable product.
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/ProductType.kt
Outdated
Show resolved
Hide resolved
| } | ||
| } | ||
|
|
||
| private fun getItemIdIfVariableProductIsAlreadySelected(product: com.woocommerce.android.model.Product): Long? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Np: you may consider using
import com.woocommerce.android.model.Product as ModelProduct
To make it a bit more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here ff6c60d
| selectedItems + SelectedItem.ProductVariation( | ||
| productId = product.parentId, | ||
| variationId = product.remoteId | ||
| getItemIdIfVariableProductIsAlreadySelected(product)?.let { itemId -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: It took me some time to figure out this code. Maybe to put these a bit more streightforward:
when (val alreadySelectedItemId = getItemIdIfVariableProductIsAlreadySelected(product)) {
null -> onProductsSelected(selectedItems +
SelectedItem.ProductVariation(
productId = product.parentId,
variationId = product.remoteId
)
)
else -> onIncreaseProductsQuantity(alreadySelectedItemId)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here ff6c60d
|
I notice that I can not add variable products via scanning. No error is shown. The issue comes from this code from my quick debugging (check SKU: 05-23--12-39.mp4 |
|
Thanks for the review @kidinov
Hmm. I believe we cannot add the parent variable product as is right? We should select the specific variant of the product. Example: AC-1, AC-2. Even with adding the products manually, we should select the specific variant and cannot add the parent variable product itself. Right? |
…instead add a separate variation type.
…ue/9081-increment-product-quantity # Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditViewModel.kt
It sounds about right. But still - this case is swollen, while we have all the info to handle that. We may want to show a message/snack bar that explains that the parent product can not be added to the order |
Generated by 🚫 dangerJS |
| } | ||
|
|
||
| private fun sendAddingProductsViaScanningFailedEvent( | ||
| @StringRes message: Int = string.order_creation_barcode_scanning_unable_to_add_product |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably in the parent PR, you will use different strings for 2 different error handling, so I guess having a default value here doesn't make any good?
Also, np: we usually use R.string import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Done here ed8b7e8
| ?.takeIf { it.isNotEmpty() } | ||
| ?.find { it.productId == 10L } | ||
| ?.let { assertThat(it.quantity).isEqualTo(3f) } | ||
| ?: Assertions.fail("Expected an item with productId 10L with quantity as 3") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: usually in test we use static imports for assertions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here ed8b7e8
|
Not related to the PR, but we make the same architecture mistake here as with IPP/TTP when we tight application-scoped things to VM scope. Try to enable don't keep activity and see that it all falls apart. We are not subscribed to the emitter, and instead of using StateFlow, we use stateless flow so the result is lost Maybe create a ticket and think if and how it should be addressed 05-24--11-52.mp4 |
|
Is this expected that the snackbar stays forever? 05-24--11-57.mp4 |
kidinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good to me. I left a couple of non blocking comments, and a couple of not related to the PR but related to the feature itself
…ue/9081-increment-product-quantity # Conflicts: # WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditViewModel.kt # WooCommerce/src/main/res/values/strings.xml
Yup. This is a known issue and I'll take care of this as soon as the first release is out. These are the things that I'll be taking care of after the first release Let me know if I've missed anything here. |
Yes. In order to dismiss it. You need to swipe right. |
Hm, feels not really Android way of showing errors then. I'd vote for using dismissive snackbars for this purpose then |
Closes: #9081
Description
Before this PR
When you scan the same product more than once, the same product was being added to the list in a separate row instead of just incrementing the already existing product count.
After this PR
When you scan the same product more than once, the product quantity gets incremented as expected.
Testing instructions
Images/gif
Please ignore the scanner not displaying the camera session. It's something to do with Google play services. It's messed up on my device, again.
screen-20230522-174950.2.mp4
RELEASE-NOTES.txtif necessary.