Skip to content

[WOMOB-178][POS] Coupons Checkout Screen - Happy Path #13987

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

Open
wants to merge 22 commits into
base: trunk
Choose a base branch
from

Conversation

malinajirka
Copy link
Contributor

@malinajirka malinajirka commented Apr 29, 2025

Closes: #WOOMOB-178

Description

This PR updates coupons on the checkout screen to match designs - happy path only.

The coupon in the cart is green and contains the discount after the order is created. The cart item is reverted if the user goes back to the product selection screen. Lastly, the totals section is re-ordered and rephrased.

This PR also updates the success/onSuccess colors to match the updated Design System.

Known issues:

Testing information

No Coupon

  1. Open POS
  2. Add a product to the cart
  3. Move to checkout
  4. Verify Discount total section is hidden and the flow works as expected.

Coupon Added

  1. Open POS
  2. Add a product to the cart
  3. Add a coupon to the cart
  4. Move to checkout
  5. Notice the item is green and contains the discount
  6. Notice totals section contains the discount

Multiple coupons added

  1. Open POS
  2. Add a product to the cart
  3. Add a couple coupons to the cart
  4. Move to checkout
  5. Notice both coupons are green and contain discount
  6. Notice totals section contains the total discount

The tests that have been performed

I have verified the above.

Images/gif

Designs Implementation
Light Products
Light Checkout
Dark Products
Dark Checkout
  • 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.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

…count-in-cart

# Conflicts:
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/cart/WooPosCartScreen.kt
#	WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/cart/WooPosCartViewModel.kt
@malinajirka malinajirka requested review from kidinov and Copilot April 29, 2025 11:28
Copy link
Contributor

@Copilot 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 updates the coupons checkout screen for the happy path by aligning the UI, tests, and event communication with the latest designs. Key changes include:

  • Updating tests to verify proper coupon discount formatting and event handling.
  • Refactoring naming from cartProductUpdater to cartItemsUpdater across multiple modules.
  • Adjusting UI components and logging to support coupon discount displays and error reporting.

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
WooPosTotalsViewModelTest.kt Added tests for coupon discount text correctness and handling of invalid coupons.
WooPosCartViewModelTest.kt Updated dependency and null handling for formatted coupon discounts in the cart.
WooPosCartItemsUpdaterTest.kt Revised tests to verify the updated coupons logic and reporting in cart items updater.
WooPosTotalsViewModel.kt Adjusted coupon discount formatting and mapping of coupon lines from orders.
WooPosCartScreen.kt Modified UI to conditionally style coupon items based on calculated discount.
WooPosCartItemsUpdater.kt Updated coupon processing to include logging and crash reporting when a coupon is missing.
WooPosHomeViewModel.kt & Communication Files Updated data structures and event communication for coupons.
WooPosTheme.kt Revised color definitions for success states in the design system.
Files not reviewed (1)
  • WooCommerce/src/main/res/values/strings.xml: Language not supported
Comments suppressed due to low confidence (2)

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/cart/WooPosCartItemsUpdater.kt:87

  • [nitpick] Consider including the coupon code (e.g., item.name) in the error message to improve debugging when the coupon cannot be found.
val message = "Coupon not found in the cart"

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/totals/WooPosTotalsViewModel.kt:490

  • [nitpick] If coupon parsing failures are an expected occurrence, consider logging a warning instead of an error to prevent over-reporting.
wooLogWrapper.e(POS, "Parsing coupon failed, discount: ${it.discount}, code: ${it.code}, id: ${it.id}")

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Apr 29, 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
Commit079fa79
Direct Downloadwoocommerce-wear-prototype-build-pr13987-079fa79.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Apr 29, 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
Commit079fa79
Direct Downloadwoocommerce-prototype-build-pr13987-079fa79.apk

@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 22.3. 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

@kidinov kidinov self-assigned this Apr 30, 2025
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 58.62069% with 36 lines in your changes missing coverage. Please review.

Project coverage is 38.32%. Comparing base (3551dd5) to head (079fa79).
Report is 201 commits behind head on trunk.

Files with missing lines Patch % Lines
...android/ui/woopos/home/cart/WooPosCartViewModel.kt 10.52% 17 Missing ⚠️
...oopos/common/composeui/designsystem/WooPosTheme.kt 0.00% 8 Missing ⚠️
...erce/android/ui/woopos/home/WooPosHomeViewModel.kt 16.66% 5 Missing ⚠️
...roid/ui/woopos/home/cart/WooPosCartItemsUpdater.kt 80.00% 0 Missing and 3 partials ⚠️
...oid/ui/woopos/home/totals/WooPosTotalsViewModel.kt 86.36% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #13987      +/-   ##
============================================
+ Coverage     38.30%   38.32%   +0.02%     
- Complexity     9495     9503       +8     
============================================
  Files          2116     2116              
  Lines        116422   116494      +72     
  Branches      14919    14922       +3     
============================================
+ Hits          44592    44644      +52     
- Misses        67747    67760      +13     
- Partials       4083     4090       +7     

☔ 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.

@@ -65,6 +68,12 @@ sealed class ParentToChildrenEvent {
val variationId: Long,
) : ProductInfo(id, name, price, quantity)
}

data class CouponLine(
Copy link
Contributor

Choose a reason for hiding this comment

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

np: I think we should call it either CouponInfo or rename to ProductLine for consistance

private suspend fun updateCouponsWithFormattedDiscount(
updatedCoupons: List<ParentToChildrenEvent.OrderCreated.CouponLine>,
item: WooPosCartItemViewState.Coupon,
) = updatedCoupons.find { it.code == item.name }?.let {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ok, that apparently the same is called "code" in one place and "name" in another?

if (isDiscountCalculated) {
Spacer(modifier = Modifier.height(WooPosSpacing.XSmall.value.toAdaptivePadding()))
WooPosText(
text = requireNotNull(item.formattedDiscount) { "Can't be null" },
Copy link
Contributor

Choose a reason for hiding this comment

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

np: seems redundant message as it doesn't provide anything extra

text = requireNotNull(item.formattedDiscount),

@@ -420,7 +423,7 @@ class WooPosTotalsViewModel @Inject constructor(
.fold(
onSuccess = { order -> handleCreatedOrder(order) },
onFailure = { error ->
WooLog.e(T.POS, "Order creation failed - $error")
WooLog.e(POS, "Order creation failed - $error")
Copy link
Contributor

Choose a reason for hiding this comment

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

np: if we inject wooLogWrapper, then maybe to use it here too

code = it.code,
discountAmount = BigDecimal(it.discount)
)
} catch (e: NumberFormatException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

np: e is unused

} catch (_: NumberFormatException) {

@kidinov kidinov self-requested a review April 30, 2025 11:23
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.

Looks great! I left a couple of NPs, please take a look!

Some general feedback:

  • It's possible to checkout with just a coupon, with not products
  • When the discount is shown on the coupon, we move from 2 lines to 3
image image

And this creates a small jaggering effect. Maybe to add a quite, subtle animation the this state change?

  • Also maybe consider adding animation on the color change from what it is to the green one
  • When we go from the checout, we kind a"unapply" the coupon, but the reduced price of the coupons stay there
image image

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

Successfully merging this pull request may close these issues.

5 participants