Skip to content
Browse files

Decode HTML Entities in rate hash.

Handy for bilingual XML, Canada Post returns some fancy xml such as
"Postes Canada Colis accélérés"
  • Loading branch information...
1 parent c70efbf commit 2ec0b19a1339071152fbab763c5a042dbf1dbc49 @jbourassa jbourassa committed with j15e
Showing with 5 additions and 1 deletion.
  1. +5 −1 app/models/spree/calculator/active_shipping/base.rb
6 app/models/spree/calculator/active_shipping/base.rb
@@ -79,7 +79,11 @@ def retrieve_rates(origin, destination, packages)
response = carrier.find_rates(origin, destination, packages)
# turn this beastly array into a nice little hash
- rate_hash = Hash[*response.rates.collect { |rate| [rate.service_name, rate.price] }.flatten]
+ # 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]
+ end
+ rate_hash = Hash[*rates.flatten]
return rate_hash
rescue ActiveMerchant::ActiveMerchantError => e

0 comments on commit 2ec0b19

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