Navigation Menu

Skip to content

Commit

Permalink
Clear shipment when transitioning to delivery step of
Browse files Browse the repository at this point in the history
checkout if the current shipping address is not eligible for the
existing shipping method

[Fixes #925]
  • Loading branch information
LBRapid authored and radar committed Jun 6, 2012
1 parent 71a3c4f commit aae64f1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/app/models/spree/order.rb
Expand Up @@ -94,9 +94,7 @@ class Order < ActiveRecord::Base
end
end

before_transition :to => ['delivery'] do |order|
order.shipments.each { |s| s.destroy unless s.shipping_method.available_to_order?(order) }
end
before_transition :to => 'delivery', :do => :remove_invalid_shipments!

after_transition :to => 'complete', :do => :finalize!
after_transition :to => 'delivery', :do => :create_tax_charge!
Expand Down Expand Up @@ -338,6 +336,12 @@ def tax_total
adjustments.tax.map(&:amount).sum
end

# Clear shipment when transitioning to delivery step of checkout if the
# current shipping address is not eligible for the existing shipping method
def remove_invalid_shipments!
shipments.each { |s| s.destroy unless s.shipping_method.available_to_order?(self) }
end

# Creates new tax charges if there are any applicable rates. If prices already
# include taxes then price adjustments are created instead.
def create_tax_charge!
Expand Down

0 comments on commit aae64f1

Please sign in to comment.