Permalink
Browse files

Add force_volume_volume_discount_update method.

  • Loading branch information...
1 parent bffb250 commit 3798d42c36bcaf1a4b3740a9d9521ca030849c81 Adam Wróbel committed Apr 13, 2011
Showing with 8 additions and 6 deletions.
  1. +8 −6 app/models/order_decorator.rb
@@ -27,27 +27,29 @@ def update_totals_with_volume_discount
end
alias_method_chain :update_totals, :volume_discount
- # This is required for Volume Customers
- # It updates item_total when user logs in
- def update_totals_on_user_association
- return unless user_id_changed? || email_changed?
+ def volume_user_changed?
+ user_id_changed? || email_changed?
+ end
+ def force_volume_discount_update
products_to_update = []
line_items.each do |li|
if li.variant.requires_per_product_discount?
products_to_update << li.variant.product
else
li.update_volume_discount self
- li.save
+ li.save if li.persisted?
end
end
products_to_update.uniq.each {|p| update_product_volume_discount p}
update_totals
end
- before_save :update_totals_on_user_association
+ # This is required for Volume Customers
+ # It updates item_total when user logs in
+ before_save :force_volume_discount_update, :if => :volume_user_changed?
def update_product_volume_discount product
line_items true

0 comments on commit 3798d42

Please sign in to comment.