Skip to content

[Woo POS] Coupons: Disallow adding duplicate coupons to cart #15551

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 4 commits into
base: trunk
Choose a base branch
from

Conversation

iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Apr 25, 2025

Description

Partially addresses WOOMOB-259 by disallowing duplicated coupons to be added to the cart, while we get feedback from design on how to handle it UI-wise.

We also avoid calling the pos_coupon_added_to_cart track event multiple times by creating a new implementation for POSItemActionHandler, otherwise we could see the track event called multiple times despite the action being disallowed, as we used the same action handler across products and coupons:

🔵 Tracked pos_coupon_added_to_cart, properties: [blog_id: -1, is_wpcom_store: false, plan: , was_ecommerce_trial: false, site_url: https://indiemelon.mystagingwebsite.com, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f]
🔵 Tracked pos_coupon_added_to_cart, properties: [is_wpcom_store: false, plan: , store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, was_ecommerce_trial: false, blog_id: -1, site_url: https://indiemelon.mystagingwebsite.com]
🔵 Tracked pos_coupon_added_to_cart, properties: [site_url: https://indiemelon.mystagingwebsite.com, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, plan: , is_wpcom_store: false, blog_id: -1, was_ecommerce_trial: false]

Testing information

  • In POS, add a coupon to the cart
  • Try again, observe how nothing happens. Removing it allows to be re-added.
  • Confirm the pos_coupon_added_to_cart event is only logged once, when we add the coupon to the cart
  • Confirm that adding products and variations to cart still work as expected.

Screenshots

Screen.Recording.2025-04-25.at.10.34.12.mov

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.

We cannot extract the function to make SUT for the whole test suite (at least not straight-away) as crashes due analytics running on different threads that we expect for each enum in the test suite.
Despite disallowing for duplicated coupons to be added to cart, the action handler is generic to all items so we were still calling the tracking event. We create a handler specifically for coupons to avoid calling the event when it shouldnt
@iamgabrielma iamgabrielma added type: task An internally driven task. feature: coupons Related to basic fulfillment such as order tracking. feature: POS labels Apr 25, 2025
@iamgabrielma iamgabrielma added this to the 22.3 milestone Apr 25, 2025
@iamgabrielma iamgabrielma marked this pull request as ready for review April 25, 2025 04:05
@iamgabrielma iamgabrielma requested a review from staskus April 25, 2025 04:06
@wpmobilebot
Copy link
Collaborator

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Number29487
VersionPR #15551
Bundle IDcom.automattic.alpha.woocommerce
Commit72e42f7
Installation URL3ajv3v99nksag
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@staskus
Copy link
Contributor

staskus commented Apr 25, 2025

@iamgabrielma thanks for the work!

Let's wait before merging until we get input from design. I think it's better right now to show an error in the checkout rather than not allow tapping the item without any visual signal.

Also, let's clarify if the item should be tappable when it's disabled (including the expired one). Maybe we wouldn't need a separate item handler logic.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: coupons Related to basic fulfillment such as order tracking. feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants