Permalink
Browse files

Copy master volume prices to new variants.

  • Loading branch information...
1 parent cded7f2 commit 42593f50c07ed3d7100256cebbc2442214767215 @amw amw committed Feb 27, 2011
Showing with 10 additions and 0 deletions.
  1. +10 −0 app/models/variant_decorator.rb
View
10 app/models/variant_decorator.rb
@@ -7,6 +7,8 @@
:reject_if => :blank_volume_price,
:allow_destroy => true
+ after_create :copy_master_volume_prices
+
# calculates the price based on quantity
def volume_price quantity, order = nil
quantity += order.variant_starting_quantity self if order
@@ -22,4 +24,12 @@ def volume_price quantity, order = nil
def blank_volume_price attributes
attributes['starting_quantity'].blank? && attributes['price'].blank?
end
+
+ private
+ def copy_master_volume_prices
+ return if self.is_master?
+ self.volume_prices = self.product.master.volume_prices.map do |vp|
+ VolumePrice.new vp.attributes.slice('starting_quantity', 'price')
+ end
+ end
end

0 comments on commit 42593f5

Please sign in to comment.