diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index fb967fbe71..81efb2dc0d 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -19,16 +19,12 @@ Spree::Order.class_eval 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 + # Fix for #2191 + if order.shipping_method.andand.require_ship_address and order.ship_address + order.create_shipment! + order.update_totals end + order.payment_required? } 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? } @@ -136,6 +132,9 @@ Spree::Order.class_eval do end end + def available_shipping_methods(display_on = nil) + Spree::ShippingMethod.all_available(self, display_on) + end private def shipping_address_from_distributor @@ -143,7 +142,8 @@ Spree::Order.class_eval do # This method is confusing to conform to the vagaries of the multi-step checkout # We copy over the shipping address when we have no shipping method selected # We can refactor this when we drop the multi-step checkout option - if shipping_method.nil? or shipping_method.andand.require_ship_address == false + # + if shipping_method.andand.require_ship_address == false self.ship_address = distributor.address.clone if bill_address diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index 64f48bae28..bfb4ce2bb6 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -25,6 +25,14 @@ Spree::ShippingMethod.class_eval do end alias_method_chain :available_to_order?, :distributor_check + def within_zone?(order) + if order.ship_address + zone && zone.include?(order.ship_address) + else + true # Shipping methods are available before we've selected an address + end + end + def adjustment_label 'Delivery' end diff --git a/spec/controllers/shop/checkout_controller_spec.rb b/spec/controllers/shop/checkout_controller_spec.rb index ae560a26b8..fd33e84b88 100644 --- a/spec/controllers/shop/checkout_controller_spec.rb +++ b/spec/controllers/shop/checkout_controller_spec.rb @@ -36,4 +36,16 @@ describe Shop::CheckoutController do get :edit response.should be_success end + + describe "building the order" do + before do + controller.stub(:current_distributor).and_return(distributor) + 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 + get :edit + assigns[:order].ship_address.address1.should be_nil + end + end end diff --git a/spec/features/consumer/checkout_spec.rb b/spec/features/consumer/checkout_spec.rb index 29a7eed19d..b55cc7821a 100644 --- a/spec/features/consumer/checkout_spec.rb +++ b/spec/features/consumer/checkout_spec.rb @@ -297,7 +297,7 @@ feature %q{ click_link 'Garlic' click_button 'Add To Cart' - click_link 'Checkout' + find('#checkout-link').click # -- Checkout: Address fill_in_fields('order_bill_address_attributes_firstname' => 'Joe', @@ -362,7 +362,7 @@ feature %q{ click_link 'Zucchini' click_button 'Add To Cart' - click_link 'Checkout' + find('#checkout-link').click # -- Checkout: Address fill_in_fields('order_bill_address_attributes_firstname' => 'Joe', @@ -391,12 +391,15 @@ feature %q{ click_checkout_continue_button # -- Checkout: Delivery + page.should have_content "DELIVERY METHOD" order_charges = page.all("tbody#summary-order-charges tr").map {|row| row.all('td').map(&:text)}.take(2) - order_charges.should == [["Delivery:", "$0.00"], ["Distribution:", "$51.00"]] + order_charges.should == [["Distribution:", "$51.00"]] + click_checkout_continue_button # -- Checkout: Payment # Given the distributor I have selected for my order, I should only see payment methods valid for that distributor + page.should have_content "PAYMENT INFORMATION" page.should have_selector 'label', :text => @payment_method_distributor_oc.name page.should_not have_selector 'label', :text => @payment_method_alternative.name click_checkout_continue_button @@ -439,7 +442,7 @@ feature %q{ click_link 'Zucchini' click_button 'Add To Cart' - click_link 'Checkout' + find('#checkout-link').click # -- Login # We perform login inline because: @@ -477,8 +480,7 @@ feature %q{ # -- Checkout: Delivery order_charges = page.all("tbody#summary-order-charges tr").map {|row| row.all('td').map(&:text)}.take(2) - order_charges.should == [["Delivery:", "$0.00"], - ["Distribution:", "$51.00"]] + order_charges.should == [["Distribution:", "$51.00"]] click_checkout_continue_button # -- Checkout: Payment diff --git a/spec/models/spree/shipping_method_spec.rb b/spec/models/spree/shipping_method_spec.rb index b2aad5b4db..d6b821e890 100644 --- a/spec/models/spree/shipping_method_spec.rb +++ b/spec/models/spree/shipping_method_spec.rb @@ -49,6 +49,11 @@ module Spree distributor: build(:distributor_enterprise)) sm.should_not be_available_to_order o end + + it "is available to orders with no shipping address" do + o = build(:order, ship_address: nil, distributor: sm.distributors.first) + sm.should be_available_to_order o + end end end end