diff --git a/app/controllers/shop/checkout_controller.rb b/app/controllers/shop/checkout_controller.rb index e9bd3ca384..b253128d3e 100644 --- a/app/controllers/shop/checkout_controller.rb +++ b/app/controllers/shop/checkout_controller.rb @@ -11,31 +11,27 @@ class Shop::CheckoutController < Spree::CheckoutController end def update - begin - if @order.update_attributes(params[:order]) - fire_event('spree.checkout.update') + if @order.update_attributes(params[:order]) + fire_event('spree.checkout.update') - while @order.state != "complete" - if @order.next - state_callback(:after) - else - flash[:error] = t(:payment_processing_failed) - respond_with @order, location: main_app.shop_checkout_path - return - end - end - - if @order.state == "complete" || @order.completed? - flash.notice = t(:order_processed_successfully) - flash[:commerce_tracking] = "nothing special" - respond_with(@order, :location => order_path(@order)) + while @order.state != "complete" + if @order.next + state_callback(:after) else + flash[:error] = t(:payment_processing_failed) respond_with @order, location: main_app.shop_checkout_path + return end + end + + if @order.state == "complete" || @order.completed? + flash.notice = t(:order_processed_successfully) + flash[:commerce_tracking] = "nothing special" + respond_with(@order, :location => order_path(@order)) else respond_with @order, location: main_app.shop_checkout_path end - rescue ActiveRecord::RecordInvalid + else respond_with @order, location: main_app.shop_checkout_path end end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index ad40e4302d..b8bde38922 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -14,6 +14,26 @@ Spree::Order.class_eval do before_validation :shipping_address_from_distributor + checkout_flow do + go_to_state :address + go_to_state :delivery + go_to_state :payment, :if => lambda { |order| + if order.ship_address.andand.valid? + # Fix for #2191 + if order.shipping_method + order.create_shipment! + order.update_totals + end + order.payment_required? + else + false + end + } + go_to_state :confirm, :if => lambda { |order| order.confirmation_required? } + go_to_state :complete, :if => lambda { |order| (order.payment_required? && order.has_unprocessed_payments?) || !order.payment_required? } + remove_transition :from => :delivery, :to => :confirm + end + # -- Scopes scope :managed_by, lambda { |user| diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index f995edaa83..ffdc1cde8d 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -160,7 +160,7 @@ feature "As a consumer I want to check out my cart", js: true do end describe "Purchasing" do - pending "re-renders with errors when we submit the incomplete form" do + it "re-renders with errors when we submit the incomplete form" do choose sm2.name click_button "Purchase" current_path.should == "/shop/checkout" @@ -170,17 +170,20 @@ feature "As a consumer I want to check out my cart", js: true do it "renders errors on the shipping method where appropriate" it "takes us to the order confirmation page when we submit a complete form" do - fill_in "Customer E-Mail", with: "test@test.com" - fill_in "Phone", with: "0468363090" - fill_in "First Name", with: "Will" - fill_in "Last Name", with: "Marshall" - fill_in "Billing Address", with: "123 Your Face" - select "Australia", from: "Country" - select "Victoria", from: "State" - fill_in "City", with: "Melbourne" - fill_in "Zip Code", with: "3066" - choose sm1.name + choose sm2.name choose pm1.name + within "#details" do + fill_in "First Name", with: "Will" + fill_in "Last Name", with: "Marshall" + save_and_open_page + fill_in "Billing Address", with: "123 Your Face" + select "Australia", from: "Country" + select "Victoria", from: "State" + fill_in "Customer E-Mail", with: "test@test.com" + fill_in "Phone", with: "0468363090" + fill_in "City", with: "Melbourne" + fill_in "Zip Code", with: "3066" + end click_button "Purchase" page.should have_content "Your order has been processed successfully" end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 6cd67ae569..91525cb83a 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -274,14 +274,20 @@ describe Spree::Order do order.shipping_method = create(:shipping_method, require_ship_address: false) order.ship_address.update_attribute :firstname, "will" order.save - order.ship_address.firstname.should == distributor.address.firstname + order.ship_address.firstname.shoul == distributor.address.firstname end + it "does not populate the shipping address if the shipping method requires a delivery address" do order.shipping_method = create(:shipping_method, require_ship_address: true) order.ship_address.update_attribute :firstname, "will" order.save order.ship_address.firstname.should == "will" end + + it "doesn't attempt to create a shipment if the order is not yet valid" do + #Shipment.should_not_r + order.create_shipment! + end end end