Module: Workarea::AddressesHelper
- Defined in:
- app/helpers/workarea/addresses_helper.rb
Instance Method Summary collapse
- #country_options ⇒ Object
- #formatted_address(address) ⇒ Object
- #is_usa_only? ⇒ Boolean
- #region_options ⇒ Object
Instance Method Details
#country_options ⇒ Object
3 4 5 6 7 8 |
# File 'app/helpers/workarea/addresses_helper.rb', line 3 def return [[Country['US'].name, Country['US'].alpha2]] if is_usa_only? Workarea.config.countries.map do |country| [country.name, country.alpha2] end end |
#formatted_address(address) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/workarea/addresses_helper.rb', line 31 def formatted_address(address) pieces = { recipient: "#{address.first_name} #{address.last_name}\n#{address.company}".strip, street: "#{address.street} #{address.street_2}".strip, city: address.city, region: address.region_name, region_short: address.region, postalcode: address.postal_code, country: address.country.alpha2 } address_format = address.country.address_format || Country['US'].address_format result = pieces.reduce(address_format) do |memo, (name, value)| memo.gsub(/{{#{name}}}/, html_escape(value.to_s)) end if address.phone_number.present? formatted_phone = number_to_phone( address.phone_number, extension: address.phone_extension ) result << "\n#{formatted_phone}" end result.gsub(/\n/, tag(:br)).html_safe end |
#is_usa_only? ⇒ Boolean
21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/workarea/addresses_helper.rb', line 21 def is_usa_only? orders = current_order rescue nil return false if orders.blank? || orders.items.blank? usa_only_attribute = Workarea.config.shipping_attributes[:usa_only] product_attributes = orders.items.map(&:product_attributes) return product_attributes.map{ |item| item[:details][:en][usa_only_attribute] }.flatten.include?("true") end |
#region_options ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/workarea/addresses_helper.rb', line 10 def ||= Workarea.config.countries.reduce([]) do |memo, country| regions = country.subdivisions .map { |id, region| [region.translations[I18n.locale.to_s] || region.name, id] } .sort_by { |name, id| name || id } memo << [country.name, regions] memo end end |