Skip to content
Browse files

Add support for localizing of Variant#cost_price

  • Loading branch information...
1 parent b4f86e6 commit d8bea3ebd26230cbda51e8ba0447be77633ccfe8 @radar committed Mar 13, 2012
Showing with 18 additions and 3 deletions.
  1. +5 −2 app/models/spree/variant_decorator.rb
  2. +7 −1 lib/spree_localize.rb
  3. +6 −0 spec/models/de/product_spec.rb
View
7 app/models/spree/variant_decorator.rb
@@ -2,7 +2,10 @@
alias_method :old_price=, :price=
def price=(value)
- normalized_price = value.to_s.gsub(",", ".")
- self.old_price = normalized_price.to_f
+ self.old_price = SpreeLocalize.normalize_number(value)
+ end
+
+ def cost_price=(value)
+ write_attribute(:cost_price, SpreeLocalize.normalize_number(value))
end
end
View
8 lib/spree_localize.rb
@@ -1,5 +1,11 @@
require 'i18n'
require 'rails-i18n'
-
require 'spree_core'
+
require 'spree_localize/engine'
+
+module SpreeLocalize
+ def self.normalize_number(number)
+ number.to_s.tr(',', '.').to_f
+ end
+end
View
6 spec/models/de/product_spec.rb
@@ -19,5 +19,11 @@
product.update_attributes(:price => "9,99")
product.price.should == 9.99
end
+
+ it "can assign the cost_price attribute" do
+ product = Spree::Product.new
+ product.cost_price = "9,99"
+ product.cost_price.to_f.should == 9.99
+ end
end
end

0 comments on commit d8bea3e

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