Module: Spree::BaseHelper

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

Instance Method Summary collapse

Instance Method Details



43
44
45
46
47
48
49
# File 'app/helpers/spree/base_helper.rb', line 43

def add_product_link(text, product) 
  link_to_remote text, {:url => {:controller => "cart", 
            :action => "add", :id => product}}, 
            {:title => "Add to Cart", 
             :href => url_for( :controller => "cart", 
                        :action => "add", :id => product)} 
end

this should be cart_path since it returns path only didn’t wan’t to change until we know what breaks so I named new helpers differently below - WN



6
7
8
9
# File 'app/helpers/spree/base_helper.rb', line 6

def cart_link
  return new_order_url if session[:order_id].blank?
  return edit_order_url(Order.find_or_create_by_id(session[:order_id]))
end

#cart_pathObject



11
12
13
# File 'app/helpers/spree/base_helper.rb', line 11

def cart_path
  cart_link
end


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

def link_to_cart(text=t('cart'))
  path = cart_path
  order = Order.find_or_create_by_id(session[:order_id]) unless session[:order_id].blank?
  css_class = ''
  unless order.nil?
    item_count = order.line_items.inject(0) { |kount, line_item| kount + line_item.quantity }
    return "" if current_page?(path)
    text = "#{text}: (#{item_count}) #{order_price(order)}"
    css_class = 'full' if item_count > 0
  end
  link_to text, path, :class => css_class
end

#logo(image_path = ) ⇒ Object



131
132
133
# File 'app/helpers/spree/base_helper.rb', line 131

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

#meta_data_tagsObject



100
101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/spree/base_helper.rb', line 100

def 
  return unless self.respond_to?(:object) && 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

#mini_image(product) ⇒ Object



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

def mini_image(product)
  if product.images.empty?
    image_tag "noimage/mini.jpg"  
  else
    image_tag product.images.first.attachment.url(:mini)  
  end
end

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



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/spree/base_helper.rb', line 29

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

#product_image(product) ⇒ Object



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

def product_image(product)
  if product.images.empty?
    image_tag "noimage/product.jpg"  
  else
    image_tag product.images.first.attachment.url(:product)  
  end
end


51
52
53
54
55
56
57
58
# File 'app/helpers/spree/base_helper.rb', line 51

def remove_product_link(text, product) 
  link_to_remote text, {:url => {:controller => "cart", 
                     :action => "remove", 
                     :id => product}}, 
                     {:title => "Remove item", 
                       :href => url_for( :controller => "cart", 
                                   :action => "remove", :id => product)} 
end

#small_image(product) ⇒ Object



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

def small_image(product)
  if product.images.empty?
    image_tag "noimage/small.jpg"  
  else
    image_tag product.images.first.attachment.url(:small)  
  end
end

#stylesheet_pathsObject



122
123
124
125
126
127
128
129
# File 'app/helpers/spree/base_helper.rb', line 122

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

#stylesheet_tags(paths = stylesheet_paths) ⇒ Object



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

def stylesheet_tags(paths=stylesheet_paths)
  output = ''
  if !paths.blank?
    paths.each do |path|
      output << stylesheet_link_tag(path)
    end
  end
  return output
end

#todays_short_dateObject



60
61
62
# File 'app/helpers/spree/base_helper.rb', line 60

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



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

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 (v.in_stock? or allow_back_orders)
  list
end

#yesterdays_short_dateObject



64
65
66
# File 'app/helpers/spree/base_helper.rb', line 64

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