Skip to content

Add can apply to promotions#6013

Merged
tvdeyen merged 4 commits intosolidusio:mainfrom
mamhoff:add-can-apply-to-promotions
Dec 5, 2024
Merged

Add can apply to promotions#6013
tvdeyen merged 4 commits intosolidusio:mainfrom
mamhoff:add-can-apply-to-promotions

Conversation

@mamhoff
Copy link
Copy Markdown
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
Copy Markdown
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
@codecov
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@github-actions
Copy link
Copy Markdown

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