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

A promotion without actions should log errors #3365

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/app/models/spree/promotion_handler/coupon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def apply
handle_present_promotion(promotion)
elsif promotion_code && promotion_code.promotion.inactive?
set_error_code :coupon_code_expired
elsif promotion_code && !promotion.actions.exists?
set_error_code :coupon_code_not_found
Rails.logger.warn I18n.t(:coupon_code_no_promotion_actions, coupon_code: coupon_code)
else
set_error_code :coupon_code_not_found
end
Expand Down
1 change: 1 addition & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ en:
coupon_code_removed: The coupon code was successfully removed from this order.
coupon_code_unknown_error: This coupon code could not be applied to the cart at
this time.
coupon_code_no_promotion_actions: "Failed to apply the coupon code '%{coupon_code}' because it does not have any actions."
create: Create
create_a_new_account: Create a new account
create_one: Create One.
Expand Down
6 changes: 6 additions & 0 deletions core/spec/models/spree/promotion_handler/coupon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)
subject.apply
expect(subject.error).to eq I18n.t('spree.coupon_code_not_found')
end

it "logs a warning message" do
allow(Rails.logger).to receive(:warn).at_least(:once)
subject.apply
expect(Rails.logger).to have_received(:warn).with I18n.t(:coupon_code_no_promotion_actions, coupon_code: '10off')
end
end
end

Expand Down
8 changes: 6 additions & 2 deletions guides/source/users/promotions/promotion-actions.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ following steps:
of many types of discount depending on the promotion calculator being used.
(For example, the amount could be a flat percentage or a flexible rate.)

Note that if you choose the promotion action type **Free Shipping** that steps
3. and 4. are not applicable.
### Notes
1. If you choose the promotion action type **Free Shipping**, then steps
**3** and **4** are not applicable.
2. You can set a coupon code to your promotion, but your customers will be
unable to use it when no actions are present. In these cases, a warning message
will be shown in the logs.

[create-a-new-promotion]: overview.html#create-a-new-promotion
[promotion-calculators]: promotion-calculators.html
Expand Down