forked from spree/spree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow coupon codes to be added from admin adjustments index.
Fixes spree#3859
- Loading branch information
1 parent
3bd0aa9
commit 28c7ba3
Showing
8 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
backend/app/assets/javascripts/admin/adjustments.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$(@).ready( -> | ||
$('[data-hook=adjustments_new_coupon_code] #add_coupon_code').click -> | ||
return if $("#coupon_code").val().length == 0 | ||
$.ajax | ||
type: 'PUT' | ||
url: Spree.url(Spree.routes.orders_api + '/' + order_number + '/apply_coupon_code.json'); | ||
data: | ||
coupon_code: $("#coupon_code").val() | ||
success: -> | ||
window.location.reload(); | ||
error: (msg) -> | ||
if msg.responseJSON["error"] | ||
show_flash_error msg.responseJSON["error"] | ||
else | ||
show_flash_error "There was a problem adding this coupon code." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,7 @@ | |
} | ||
} | ||
} | ||
|
||
[data-hook="adjustments_new_coupon_code"] { | ||
margin-bottom: 18px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
backend/spec/features/admin/orders/adjustments_promotions_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
|
||
describe "Adjustments Promotions" do | ||
stub_authorization! | ||
|
||
before(:each) do | ||
promotion = create(:promotion_with_item_adjustment, | ||
:name => "$10 off", | ||
:path => 'test', | ||
:code => "10_off", | ||
:starts_at => 1.day.ago, | ||
:expires_at => 1.day.from_now, | ||
:adjustment_rate => 10) | ||
|
||
order = create(:order_with_totals) | ||
line_item = order.line_items.first | ||
# so we can be sure of a determinate price in our assertions | ||
line_item.update_column(:price, 10) | ||
|
||
visit spree.admin_order_adjustments_path(order) | ||
end | ||
|
||
context "admin adding a promotion" do | ||
context "successfully" do | ||
it "should create a new adjustment", :js => true do | ||
fill_in "coupon_code", :with => "10_off" | ||
click_button "Add Coupon Code" | ||
page.should have_content("$10 off") | ||
page.should have_content("-10.00") | ||
end | ||
end | ||
|
||
context "for non-existing promotion" do | ||
it "should show an error message", :js => true do | ||
fill_in "coupon_code", :with => "does_not_exist" | ||
click_button "Add Coupon Code" | ||
page.should have_content("doesn't exist.") | ||
end | ||
end | ||
|
||
context "for already applied promotion" do | ||
it "should show an error message", :js => true do | ||
2.times { | ||
fill_in "coupon_code", :with => "10_off" | ||
click_button "Add Coupon Code" | ||
} | ||
page.should have_content("already been applied") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
core/lib/spree/testing_support/factories/promotion_factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
FactoryGirl.define do | ||
factory :promotion, class: Spree::Promotion do | ||
name 'Promo' | ||
|
||
factory :promotion_with_item_adjustment do | ||
ignore do | ||
adjustment_rate 10 | ||
end | ||
|
||
after(:create) do |promotion, evaluator| | ||
calculator = Spree::Calculator::FlatRate.new | ||
calculator.preferred_amount = evaluator.adjustment_rate | ||
action = Spree::Promotion::Actions::CreateItemAdjustments.create(:calculator => calculator) | ||
promotion.actions << action | ||
promotion.save | ||
end | ||
end | ||
|
||
end | ||
end |