Module: Spree::BaseHelper

Defined in:
app/helpers/spree/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#available_countriesObject



87
88
89
90
# File 'app/helpers/spree/base_helper.rb', line 87

def available_countries
  return Country.all unless zone = Zone.find_by_name(Spree::Config[:checkout_zone])
  zone.country_list
end

#current_orders_product_countObject



111
112
113
114
115
116
117
# File 'app/helpers/spree/base_helper.rb', line 111

def current_orders_product_count
  if current_order.blank? || current_order.item_count < 1
    return 0
  else
    return current_order.item_count
  end
end

#format_price(price, options = {}) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'app/helpers/spree/base_helper.rb', line 92

def format_price(price, options={})
  options.assert_valid_keys(:show_vat_text)
  options.reverse_merge! :show_vat_text => Spree::Config[:show_price_inc_vat]
  formatted_price = number_to_currency(price)
  if options[:show_vat_text]
    I18n.t(:price_with_vat_included, :price => formatted_price)
  else
    formatted_price
  end
end


3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/spree/base_helper.rb', line 3

def link_to_cart(text = t('cart'))
  return "" if current_page?(cart_path)
  css_class = nil
  if current_order.nil? or current_order.line_items.empty?
    text = "#{text}: (#{t('empty')})"
    css_class = 'empty'
  else
    text = "#{text}: (#{current_order.item_count}) #{order_price(current_order)}"
    css_class = 'full'
  end
  link_to text, cart_path, :class => css_class
end

#logo(image_path = ) ⇒ Object



83
84
85
# File 'app/helpers/spree/base_helper.rb', line 83

def (image_path=Spree::Config[:logo])
  link_to image_tag(image_path), root_path
end

#meta_data_tagsObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/spree/base_helper.rb', line 57

def 
  object = instance_variable_get('@'+controller_name.singularize)
  return unless object
  "".tap do |tags|
    if object.respond_to?(:meta_keywords) and object.meta_keywords.present?
      tags << tag('meta', :name => 'keywords', :content => object.meta_keywords) + "\n"
    end
    if object.respond_to?(:meta_description) and object.meta_description.present?
      tags << tag('meta', :name => 'description', :content => object.meta_description) + "\n"
    end
  end
end

#order_price(order, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/spree/base_helper.rb', line 16

def order_price(order, options={})
  options.assert_valid_keys(:format_as_currency, :show_vat_text, :show_price_inc_vat)
  options.reverse_merge! :format_as_currency => true, :show_vat_text => true

  # overwrite show_vat_text if show_price_inc_vat is false
  options[:show_vat_text] = Spree::Config[:show_price_inc_vat]

  amount =  order.item_total
  amount += Calculator::Vat.calculate_tax(order) if Spree::Config[:show_price_inc_vat]

  options.delete(:format_as_currency) ? number_to_currency(amount) : amount
end

#seo_url(taxon, product = nil) ⇒ Object

generates nested url to product based on supplied taxon



104
105
106
107
108
109
# File 'app/helpers/spree/base_helper.rb', line 104

def seo_url(taxon, product = nil)
  return '/t/' + taxon.permalink if product.nil?
  warn "DEPRECATION: the /t/taxon-permalink/p/product-permalink urls are "+
    "not used anymore. Use product_url instead. (called from #{caller[0]})"
  return product_url(product)
end

#stylesheet_pathsObject



74
75
76
77
78
79
80
81
# File 'app/helpers/spree/base_helper.rb', line 74

def stylesheet_paths
  paths = Spree::Config[:stylesheets]
  if (paths.blank?)
    []
  else
    paths.split(',')
  end
end

#stylesheet_tags(paths = stylesheet_paths) ⇒ Object



70
71
72
# File 'app/helpers/spree/base_helper.rb', line 70

def stylesheet_tags(paths=stylesheet_paths)
  paths.blank? ? '' : stylesheet_link_tag(paths, :cache => true)
end

#todays_short_dateObject



29
30
31
# File 'app/helpers/spree/base_helper.rb', line 29

def todays_short_date
  utc_to_local(Time.now.utc).to_ordinalized_s(:stub)
end

#variant_options(v, allow_back_orders = , include_style = true) ⇒ Object

human readable list of variant options



38
39
40
41
42
# File 'app/helpers/spree/base_helper.rb', line 38

def variant_options(v, allow_back_orders = Spree::Config[:allow_backorders], include_style = true)
  list = v.options_text
  list = include_style ? "<span class =\"out-of-stock\">(" + t("out_of_stock") + ") #{list}</span>" : "#{t("out_of_stock")} #{list}" unless (allow_back_orders || v.in_stock?)
  list
end

#yesterdays_short_dateObject



33
34
35
# File 'app/helpers/spree/base_helper.rb', line 33

def yesterdays_short_date
  utc_to_local(Time.now.utc.yesterday).to_ordinalized_s(:stub)
end