Skip to content

Commit

Permalink
Fix issue where Product#set_property was causing an undefined method …
Browse files Browse the repository at this point in the history
…with spree_i18n

Fixes spree-contrib/spree_i18n#301
  • Loading branch information
radar committed Oct 21, 2013
1 parent 1c4e503 commit 4fa00e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ def property(property_name)

def set_property(property_name, property_value)
ActiveRecord::Base.transaction do
property = Property.where(name: property_name).first_or_create!(presentation: property_name)
# Works around spree_i18n #301
property = if Property.exists?(name: property_name)
Property.where(name: property_name).first
else
Property.create(name: property_name, presentation: property_name)
end
product_property = ProductProperty.where(product: self, property: property).first_or_initialize
product_property.value = property_value
product_property.save!
Expand Down

0 comments on commit 4fa00e8

Please sign in to comment.