diff --git a/app/controllers/spree/admin/payments_controller_decorator.rb b/app/controllers/spree/admin/payments_controller_decorator.rb new file mode 100644 index 0000000000..df9e77f154 --- /dev/null +++ b/app/controllers/spree/admin/payments_controller_decorator.rb @@ -0,0 +1,8 @@ +# When a user fires an event, take them back to where they came from +# Responder: http://guides.spreecommerce.com/developer/logic.html#overriding-controller-action-responses + +Spree::Admin::PaymentsController.class_eval do + respond_override :fire => { :html => { :success => lambda { + redirect_to request.referer # Keeps any filter and sort prefs + } } } +end diff --git a/app/overrides/add_capture_order_shortcut.rb b/app/overrides/add_capture_order_shortcut.rb new file mode 100644 index 0000000000..f733d31531 --- /dev/null +++ b/app/overrides/add_capture_order_shortcut.rb @@ -0,0 +1,23 @@ +Deface::Override.new(:virtual_path => "spree/admin/orders/index", + :name => "add_capture_order_shortcut", + :insert_bottom => "[data-hook='admin_orders_index_row_actions']", + :partial => 'spree/admin/orders/capture' + ) + +#Resize columns to fit new button (note: this may break with a new version of spree) +Deface::Override.new(:virtual_path => "spree/admin/orders/index", + :name => "add_capture_order_shortcut_first_column", + :set_attributes => "#listing_orders colgroup col:first-child", + :attributes => {:style => "width: 12%"} #was 16% + ) +Deface::Override.new(:virtual_path => "spree/admin/orders/index", + :name => "add_capture_order_shortcut_last_column", + :set_attributes => "#listing_orders colgroup col:last-child", + :attributes => {:style => "width: 12%"} #was 8% + ) +#And align actions column (not spree standard, but looks better IMO) +Deface::Override.new(:virtual_path => "spree/admin/orders/index", + :name => "add_capture_order_shortcut_align", + :set_attributes => "[data-hook='admin_orders_index_row_actions']", + :attributes => {:class => "actions", :style => "text-align:left;"} #removes 'align-center' class + ) diff --git a/app/views/spree/admin/orders/_capture.html.haml b/app/views/spree/admin/orders/_capture.html.haml new file mode 100644 index 0000000000..80a7481066 --- /dev/null +++ b/app/views/spree/admin/orders/_capture.html.haml @@ -0,0 +1,5 @@ +-# copied from backend/app/views/spree/admin/payments/_list.html.erb + +- if order.payments.present? + - order.payments.last.actions.grep(/^capture$/).each do |action| + = link_to_with_icon "icon-#{action}", t(action), fire_admin_order_payment_path(order, order.payments.last, :e => action), :method => :put, :no_text => true, :data => {:action => action} diff --git a/spec/factories.rb b/spec/factories.rb index 199fef1dc3..a381959530 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -102,6 +102,14 @@ FactoryGirl.define do after(:create) { |c| c.set_preference(:per_kg, 0.5); c.save! } end + factory :order_with_totals_and_distributor, :parent => :order do #possibly called :order_with_line_items in newer Spree + # Ensure order has a distributor set + distributor { create(:distributor_enterprise) } + after(:create) do |order| + p = create(:simple_product, :distributors => [order.distributor]) + FactoryGirl.create(:line_item, :order => order, :product => p) + end + end end diff --git a/spec/features/admin/order_spec.rb b/spec/features/admin/order_spec.rb new file mode 100644 index 0000000000..9f51f1f0f4 --- /dev/null +++ b/spec/features/admin/order_spec.rb @@ -0,0 +1,40 @@ +require "spec_helper" + +feature %q{ + As a payment administrator + I want to capture multiple payments quickly from the one page +} do + include AuthenticationWorkflow + include WebHelper + + background do + @user = create(:user) + @order = create(:order_with_totals_and_distributor, :user => @user, :state => 'complete', :payment_state => 'balance_due') + + # ensure order has a payment to capture + create :check_payment, order: @order, amount: @order.amount + @order.finalize! + end + + context "managing orders" do + scenario "capture multiple payments from the orders index page" do + # d.cook: could also test for an order that has had payment voided, then a new check payment created but not yet captured. But it's not critical and I know it works anyway. + login_to_admin_section + + click_link 'Orders' + current_path.should == spree.admin_orders_path + + # click the 'capture' link for the order + page.find("[data-action=capture][href*=#{@order.number}]").click + + flash_message.should == "Payment Updated" + + # check the order was captured + @order.reload + @order.payment_state.should == "paid" + + # we should still be on the same page + current_path.should == spree.admin_orders_path + end + end +end