Fixing some edge cases in the addresses

This commit is contained in:
Will Marshall
2014-03-14 11:56:13 +11:00
parent 10fe24db32
commit dc95d764fe
4 changed files with 48 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -7,4 +7,4 @@
%p= @distributor.long_description.andand.html_safe
.panel
= @distributor.distributor_info.html_safe
= @distributor.distributor_info.andand.html_safe

View File

@@ -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