Permalink
Browse files

Fix for compatibility with 1.8.7 using iconv fallback

  • Loading branch information...
1 parent 8692710 commit 1a6946df34aa5a3f72987de4454ee81e57c6425f @j15e j15e committed Oct 3, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 app/models/spree/calculator/active_shipping/base.rb
@@ -3,6 +3,7 @@
#
# Digest::MD5 is used for cache_key generation.
require 'digest/md5'
+require 'iconv' if RUBY_VERSION.to_f < 1.9
require_dependency 'spree/calculator'
module Spree
@@ -83,9 +84,14 @@ def retrieve_rates(origin, destination, packages)
begin
response = carrier.find_rates(origin, destination, packages)
# turn this beastly array into a nice little hash
- # decode html entities for xml-based APIs, ie Canada Post
rates = response.rates.collect do |rate|
- [CGI.unescape_html(rate.service_name.encode("UTF-8")), rate.price]
+ # decode html entities for xml-based APIs, ie Canada Post
+ if RUBY_VERSION.to_f < 1.9
+ service_name = Iconv.iconv('UTF-8//IGNORE', 'UTF-8', rate.service_name).first
+ else
+ service_name = rate.service_name.encode("UTF-8")
+ end
+ [CGI.unescapeHTML(service_name), rate.price]
end
rate_hash = Hash[*rates.flatten]
return rate_hash

0 comments on commit 1a6946d

Please sign in to comment.