Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Copy master volume prices to new variants.

  • Loading branch information...
commit 42593f50c07ed3d7100256cebbc2442214767215 1 parent cded7f2
Adam Wróbel authored February 27, 2011

Showing 1 changed file with 10 additions and 0 deletions. Show diff stats Hide diff stats

  1. 10  app/models/variant_decorator.rb
10  app/models/variant_decorator.rb
@@ -7,6 +7,8 @@
7 7
     :reject_if => :blank_volume_price,
8 8
     :allow_destroy => true
9 9
 
  10
+  after_create :copy_master_volume_prices
  11
+
10 12
   # calculates the price based on quantity
11 13
   def volume_price quantity, order = nil
12 14
     quantity += order.variant_starting_quantity self if order
@@ -22,4 +24,12 @@ def volume_price quantity, order = nil
22 24
   def blank_volume_price attributes
23 25
     attributes['starting_quantity'].blank? && attributes['price'].blank?
24 26
   end
  27
+
  28
+  private
  29
+  def copy_master_volume_prices
  30
+    return if self.is_master?
  31
+    self.volume_prices = self.product.master.volume_prices.map do |vp|
  32
+      VolumePrice.new vp.attributes.slice('starting_quantity', 'price')
  33
+    end
  34
+  end
25 35
 end

0 notes on commit 42593f5

Please sign in to comment.
Something went wrong with that request. Please try again.