From 4fa00e83bddbb380e681d092d86fcf7a399e5125 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 16 Oct 2013 12:01:20 +1100 Subject: [PATCH] Fix issue where Product#set_property was causing an undefined method with spree_i18n Fixes spree/spree_i18n#301 --- core/app/models/spree/product.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 71972bc6ecc..f48bc562154 100755 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -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!