Skip to content
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

[Order creation] Update coupons display order details #12855

Merged

Conversation

malinajirka
Copy link
Contributor

@malinajirka malinajirka commented Nov 1, 2024

Closes: #12619 #12848
Ref: pe5pgL-5G4-p2#comment-4599

This PR updates the how coupons are displayed during Order creation to match the iOS behavior.

Changes:

  • Updated coupons behavior in the order creation to match the behavior of shipping lines.
  • Removed the ability to remove coupons from the totals bottom sheet.

Notes:

I planned to add unit tests for the added code. However, I haven't figured out how to test the code in the current state without significant refactoring. It felt like the unit tests would be tightly coupled with the inner workings of the VM, which felt off. In any case, if you have some ideas how to write reasonable tests or if you believe it's worth spending more time on, I will be happy to look into it more.

P.S. I also noticed shipping lines are editable at all times which is a bug I reported here.

Before After
Screenshot_1730470897 Screenshot_1730470794

Testing

I tested the following flows on my phone and tablet.

Case: Add coupon to order success:

  • Create a new order, observe that the + Add Coupon row is disabled.
  • Add a product to the order, observe that the + Add Coupon row is now enabled.
  • Tap on + Add Coupon -> Apply a eligible coupon to that product -> Observe how it appears in the Order, with a "trash bin" button.
  • Expand the bottom drawer, observe how the coupon appears in the order details but is not editable from there.

Case: Delete coupon from order:

  • Tap on the trash icon and observe how the coupon is removed from the order.

Case: Add coupon to order error

  • Attempt to add a non-eligible coupon to the order (for example: a coupon that is only applicable to product category A, but the order has a product category B)
  • Observe how the coupon is not added to the order, and a error notice appears at the bottom

Case: Editing an existing order

  • Open an order that has coupons applied and is not paid
  • Tap on Edit
  • Observe the coupon rows are editable normally.

Case: Editing an existing PAID order

  • Open an order that has coupons applied and is paid
  • Tap on Edit
  • Observe the coupon rows are disabled.

I also tested adding and removing shipping lines in combination with coupons with gift card extension installed/uninstalled.


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

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 all devices (phone/tablet) and no regressions are added.

@malinajirka malinajirka added type: enhancement A request for an enhancement. feature: order creation Related to the Order Creation feature labels Nov 1, 2024
@malinajirka malinajirka added this to the 21.1 milestone Nov 1, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 1, 2024

📲 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
Commiteb1f773
Direct Downloadwoocommerce-wear-prototype-build-pr12855-eb1f773.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 1, 2024

📲 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
Commiteb1f773
Direct Downloadwoocommerce-prototype-build-pr12855-eb1f773.apk

@@ -738,6 +760,22 @@ class OrderCreateEditFormFragment :
} else {
additionalInfoCollectionSection.addShippingButtonGroup.show()
}

Copy link
Contributor Author

@malinajirka malinajirka Nov 4, 2024

Choose a reason for hiding this comment

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

This code would ideally live in the VM so it could be unit tested, however, refactoring it felt like out of scope and bringing inconsistency to the surrounding code feels worse than not having this tested. I'm open to suggestions though.

@codecov-commenter
Copy link

codecov-commenter commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 17.43119% with 90 lines in your changes missing coverage. Please review.

Project coverage is 40.20%. Comparing base (995e65a) to head (eb1f773).
Report is 50 commits behind head on trunk.

Files with missing lines Patch % Lines
...ui/orders/creation/coupon/CouponLineFormSection.kt 0.00% 81 Missing ⚠️
...rders/creation/shipping/ShippingLineFormSection.kt 0.00% 4 Missing ⚠️
...s/creation/totals/OrderCreateEditTotalsFullView.kt 0.00% 3 Missing ⚠️
...oid/ui/orders/creation/OrderCreateEditViewModel.kt 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #12855      +/-   ##
============================================
- Coverage     40.24%   40.20%   -0.04%     
- Complexity     5784     5786       +2     
============================================
  Files          1247     1249       +2     
  Lines         71160    71247      +87     
  Branches       9933     9954      +21     
============================================
+ Hits          28638    28647       +9     
- Misses        39889    39966      +77     
- Partials       2633     2634       +1     

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

@malinajirka malinajirka marked this pull request as ready for review November 5, 2024 10:11
@malinajirka malinajirka marked this pull request as draft November 6, 2024 08:48
@malinajirka malinajirka marked this pull request as ready for review November 6, 2024 12:13
@dangermattic
Copy link
Collaborator

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

@samiuelson samiuelson self-assigned this Nov 7, 2024
Copy link
Contributor

@samiuelson samiuelson left a comment

Choose a reason for hiding this comment

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

Great work, @malinajirka! I added small improvement ideas. The most important seems to be the one related to long coupon codes' appearance. Feel free to ignore others.

One more thing that caught my attention is the singular form of the "Coupon" label in the bottom sheet despite multiple coupons applied (isn't it slightly confusing?). Maybe worth considering reporting an issue:

onAdd: () -> Unit,
onEdit: (id: Long) -> Unit,
onAddClicked: () -> Unit,
onEditClicked: (id: Long) -> Unit,
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@malinajirka
Copy link
Contributor Author

Thanks so much for the thorough review @samiuelson ! I have implemented all the changes except of the performance optimization.

One more thing that caught my attention is the singular form of the "Coupon" label in the bottom sheet despite multiple coupons applied (isn't it slightly confusing?). Maybe worth considering reporting an issue:

I noticed this as well but then forgot about it :X. I updated it in 18e079d. We use plural for products no matter whether there is one or multiple, so the change brings it to consistency.

Copy link
Contributor

@samiuelson samiuelson left a comment

Choose a reason for hiding this comment

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

LGTM! :shipit:

@samiuelson samiuelson merged commit fc0c7e6 into trunk Nov 7, 2024
15 checks passed
@samiuelson samiuelson deleted the issue/12619-adjust-coupons-behavior-in-order-creation branch November 7, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: order creation Related to the Order Creation feature type: enhancement A request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Applied coupon showing just in bottom details sheet
5 participants