diff --git a/app/controllers/shop/checkout_controller.rb b/app/controllers/shop/checkout_controller.rb index 1b9b3f9196..5a193e392d 100644 --- a/app/controllers/shop/checkout_controller.rb +++ b/app/controllers/shop/checkout_controller.rb @@ -23,6 +23,7 @@ class Shop::CheckoutController < Spree::CheckoutController state_callback(:after) else flash[:error] = t(:payment_processing_failed) + clear_ship_address render :edit return end @@ -33,15 +34,25 @@ class Shop::CheckoutController < Spree::CheckoutController flash[:commerce_tracking] = "nothing special" respond_with(@order, :location => order_path(@order)) else + clear_ship_address render :edit end else + clear_ship_address render :edit end end private + # When we have a pickup Shipping Method, we clone the distributor address into ship_address before_save + # We don't want this data in the form, so we clear it out + def clear_ship_address + unless current_order.shipping_method.andand.require_ship_address + current_order.ship_address = Spree::Address.default + end + end + def skip_state_validation? true end diff --git a/app/views/shop/checkout/_form.html.haml b/app/views/shop/checkout/_form.html.haml index 666943847f..fb05733c86 100644 --- a/app/views/shop/checkout/_form.html.haml +++ b/app/views/shop/checkout/_form.html.haml @@ -105,14 +105,22 @@ = sa.text_field :lastname #ship_address_hidden{"ng-show" => "order.ship_address_same_as_billing"} - = sa.hidden_field :address1, "ng-value" => "order.bill_address.address1" - = sa.hidden_field :address2, "ng-value" => "order.bill_address.address2" - = sa.hidden_field :city, "ng-value" => "order.bill_address.city" - = sa.hidden_field :country_id, "ng-value" => "order.bill_address.country_id" - = sa.hidden_field :zipcode, "ng-value" => "order.bill_address.zipcode" - = sa.hidden_field :firstname, "ng-value" => "order.bill_address.firstname" - = sa.hidden_field :lastname, "ng-value" => "order.bill_address.lastname" - = sa.hidden_field :phone, "ng-value" => "order.bill_address.phone" + = sa.hidden_field :address1, "ng-value" => "order.bill_address.address1", + "ng-disabled" => "!order.ship_address_same_as_billing" + = sa.hidden_field :address2, "ng-value" => "order.bill_address.address2", + "ng-disabled" => "!order.ship_address_same_as_billing" + = sa.hidden_field :city, "ng-value" => "order.bill_address.city", + "ng-disabled" => "!order.ship_address_same_as_billing" + = sa.hidden_field :country_id, "ng-value" => "order.bill_address.country_id", + "ng-disabled" => "!order.ship_address_same_as_billing" + = sa.hidden_field :zipcode, "ng-value" => "order.bill_address.zipcode", + "ng-disabled" => "!order.ship_address_same_as_billing" + = sa.hidden_field :firstname, "ng-value" => "order.bill_address.firstname", + "ng-disabled" => "!order.ship_address_same_as_billing" + = sa.hidden_field :lastname, "ng-value" => "order.bill_address.lastname", + "ng-disabled" => "!order.ship_address_same_as_billing" + = sa.hidden_field :phone, "ng-value" => "order.bill_address.phone", + "ng-disabled" => "!order.ship_address_same_as_billing" %fieldset#payment %legend Payment Details diff --git a/app/views/shop/shop/_about_us.html.haml b/app/views/shop/shop/_about_us.html.haml index 62eed87c86..cf48da4f81 100644 --- a/app/views/shop/shop/_about_us.html.haml +++ b/app/views/shop/shop/_about_us.html.haml @@ -7,4 +7,4 @@ %p= @distributor.long_description.andand.html_safe .panel - = @distributor.distributor_info.html_safe + = @distributor.distributor_info.andand.html_safe diff --git a/spec/controllers/shop/checkout_controller_spec.rb b/spec/controllers/shop/checkout_controller_spec.rb index c27bc2bfd9..39f5cf9dff 100644 --- a/spec/controllers/shop/checkout_controller_spec.rb +++ b/spec/controllers/shop/checkout_controller_spec.rb @@ -43,10 +43,29 @@ describe Shop::CheckoutController do controller.stub(:current_order_cycle).and_return(order_cycle) controller.stub(:current_order).and_return(order) end - it "does not clone the ship address from distributor" do + it "does not clone the ship address from distributor when shipping method requires address" do get :edit assigns[:order].ship_address.address1.should be_nil end + + it "clears the ship address when re-rendering edit" do + controller.should_receive(:clear_ship_address).and_return true + order.stub(:update_attributes).and_return false + spree_post :update, order: {} + end + + it "clears the ship address when the order state cannot be advanced" do + controller.should_receive(:clear_ship_address).and_return true + order.stub(:update_attributes).and_return true + order.stub(:next).and_return false + spree_post :update, order: {} + end + + it "only clears the ship address with a pickup shipping method" do + order.stub_chain(:shipping_method, :andand, :require_ship_address).and_return false + order.should_receive(:ship_address=) + controller.send(:clear_ship_address) + end end describe "Paypal routing" do