Permalink
Browse files

Updating master variant should also touch product

[Fixes #1583]
  • Loading branch information...
1 parent 5a7e12e commit 9bf324e47a5bfdc91a2787b616d9b953c507891f @joneslee85 joneslee85 committed with radar May 24, 2012
Showing with 3 additions and 7 deletions.
  1. +3 −7 core/app/models/spree/variant.rb
@@ -1,6 +1,6 @@
module Spree
class Variant < ActiveRecord::Base
- belongs_to :product
+ belongs_to :product, :touch => true
delegate_belongs_to :product, :name, :description, :permalink, :available_on,
:tax_category_id, :shipping_category_id, :meta_description,
:meta_keywords, :tax_category
@@ -20,8 +20,6 @@ class Variant < ActiveRecord::Base
validates :cost_price, :numericality => { :greater_than_or_equal_to => 0, :allow_nil => true } if self.table_exists? && self.column_names.include?('cost_price')
validates :count_on_hand, :numericality => true
- before_save :touch_product
-
# default variant scope only lists non-deleted variants
scope :active, where(:deleted_at => nil)
scope :deleted, where('deleted_at IS NOT NULL')
@@ -142,18 +140,16 @@ def option_value(opt_name)
self.option_values.detect { |o| o.option_type.name == opt_name }.try(:presentation)
end
+
private
+
# Ensures a new variant takes the product master price when price is not supplied
def check_price
if price.nil?
raise 'Must supply price for variant or master.price for product.' if self == product.master
self.price = product.master.price
end
end
-
- def touch_product
- product.touch unless is_master?
- end
end
end

0 comments on commit 9bf324e

Please sign in to comment.