Restoring the old checkout, but NOW our new checkout is broken

This commit is contained in:
Will Marshall
2014-03-06 16:16:00 +11:00
parent a40a0499e4
commit cc3fb27490
5 changed files with 43 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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

View File

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