Permalink
Browse files

Clear shipment when transitioning to delivery step of

checkout if the current shipping address is not eligible for the
existing shipping method

[Fixes #925]
  • Loading branch information...
1 parent 71a3c4f commit aae64f1f84d4d376903ca25d397844f473c0d30d @LBRapid LBRapid committed with radar Feb 7, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 core/app/models/spree/order.rb
@@ -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!
@@ -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!

0 comments on commit aae64f1

Please sign in to comment.