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

Add can apply to promotions #6013

Merged
merged 4 commits into from
Dec 5, 2024

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Dec 5, 2024

Summary

This fixes the orders/adjustment pages when using the new promotion system.

Bug report from @boomer196 on Slack:

Using Solidus v4.4.1 and I have the “new” promotions installed (no legacy). When I click on the Adjustments tab of an order and it blows up.
The app/views/spree/admin/adjustments/index.html.erb in solidus_backend has a check to see if it should display the coupon code section:

<% if @order.can_add_coupon? && can?(:update, @order) %>
  <div data-hook="adjustments_new_coupon_code">
    <%= text_field_tag "coupon_code", "", placeholder: t('spree.coupon_code') %>
    <%= button_tag t('spree.add_coupon_code'), id: "add_coupon_code", class: 'btn btn-primary' %>
  </div>
<% end %>

app/models/spree/order.rb has a method called can_add_coupon? and it tries to call can_apply? on the Spree::Config.promotions.coupon_code_handler_class

def can_add_coupon?
  Spree::Config.promotions.coupon_code_handler_class.new(self).can_apply?
end
ActionView::Template::Error (undefined method `can_apply?' for an instance of SolidusPromotions::PromotionHandler::Coupon):

Causes:
NoMethodError (undefined method `can_apply?' for an instance of SolidusPromotions::PromotionHandler::Coupon)

@mamhoff mamhoff requested a review from a team as a code owner December 5, 2024 14:51
@github-actions github-actions bot added the changelog:solidus_promotions Changes to the solidus_promotions gem label Dec 5, 2024
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

👌 everything here makes sense, thanks.

None of this works right now, but let's write a spec that details how
things should work.
The promotion class should decide whether it can apply.
This duplicated the logic from
SolidusPromotions::Promotion.order_activatable, and this way it reads
nicer.
@tvdeyen tvdeyen force-pushed the add-can-apply-to-promotions branch from 9a9509d to 3588c15 Compare December 5, 2024 16:08
@tvdeyen tvdeyen added the backport-v4.4 Backport this pull-request to v4.4 label Dec 5, 2024
@tvdeyen tvdeyen enabled auto-merge December 5, 2024 16:09
@tvdeyen tvdeyen merged commit dcb0dd8 into solidusio:main Dec 5, 2024
16 checks passed
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.46%. Comparing base (d0ccd7e) to head (3588c15).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6013      +/-   ##
==========================================
+ Coverage   87.81%   89.46%   +1.64%     
==========================================
  Files         476      782     +306     
  Lines       11658    18009    +6351     
==========================================
+ Hits        10238    16112    +5874     
- Misses       1420     1897     +477     

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

@mamhoff
Copy link
Contributor Author

mamhoff commented Dec 6, 2024

Not sure what happened to the Backport PR? I don't see it?

@kennyadsl kennyadsl added backport-v4.4 Backport this pull-request to v4.4 and removed backport-v4.4 Backport this pull-request to v4.4 labels Dec 6, 2024
@kennyadsl
Copy link
Member

I tried to retrigger the flow but it's still skipping it. I don't think we changed anything there recently, so it might a temporary issue with GitHub Actions.

@tvdeyen tvdeyen added backport-v4.4 Backport this pull-request to v4.4 and removed backport-v4.4 Backport this pull-request to v4.4 labels Dec 6, 2024
@tvdeyen
Copy link
Member

tvdeyen commented Dec 6, 2024

Should be fixed by #6016

@tvdeyen tvdeyen added backport-v4.4 Backport this pull-request to v4.4 and removed backport-v4.4 Backport this pull-request to v4.4 labels Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

💚 All backports created successfully

Status Branch Result
v4.4

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v4.4 Backport this pull-request to v4.4 changelog:solidus_promotions Changes to the solidus_promotions gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants