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

Let promotion handler decide whether it can add a coupon to an order #5684

Merged
merged 4 commits into from
Apr 5, 2024

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Mar 7, 2024

Summary

We have the method Spree::Order#can_add_coupon? that tells us whether an order can even accept a promotion code. Unfortunately, it directly references the Spree::Promotion class that is slated to be moved to solidus_legacy_promotions. Rather than adding a new class, I add another method to the coupon promotion handler class that does this.

I'm also adding the same method to the NullPromotionHandler for API parity.

Lastly, I realized that not all promotion handlers in core share the same API, so I alias activate to apply so that the NullPromotionHandler can be a stand-in for all promotion handlers.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@mamhoff mamhoff requested a review from a team as a code owner March 7, 2024 10:20
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Mar 7, 2024
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.91%. Comparing base (0870e75) to head (b713be7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5684   +/-   ##
=======================================
  Coverage   88.90%   88.91%           
=======================================
  Files         700      700           
  Lines       16642    16647    +5     
=======================================
+ Hits        14796    14801    +5     
  Misses       1846     1846           

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

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

I really like, but think the Null handler should be as dump as possible, no?

core/app/models/spree/null_promotion_handler.rb Outdated Show resolved Hide resolved
mamhoff added 4 commits March 12, 2024 12:39
This new method allows the order to ask the coupon promotion handler
whether an order can be modified with a promotion code.
Rather than directly referencing the Spree::Promotion ActiveRecord
model, we ask the coupon code handler.
The core coupon promotion handler now has this method, so the null
promotion handler needs it, too.
The four promotion handlers in core have two different methods to set
them into motion. Cart, Shipping, and Page use #activate, but Coupon
uses #apply. We only need one null promotion handler, and since we just
want it to return the unchanged promotion, we just alias.
@mamhoff mamhoff force-pushed the can-add-coupon-to-handler branch from 2cfcbfd to b713be7 Compare March 12, 2024 11:41
@tvdeyen tvdeyen merged commit a9ed1b5 into solidusio:main Apr 5, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants