Module: WishlistHelper

Defined in:
app/helpers/wishlist_helper.rb

Overview

Methods for display Wishlist (in totality, by product, …).

Instance Method Summary collapse

Instance Method Details

#button_add_to_wishlist(product, name = I18n.t('add_to_wishlist'), options = {}) ⇒ Object



138
139
140
141
# File 'app/helpers/wishlist_helper.rb', line 138

def button_add_to_wishlist(product, name=I18n.t('add_to_wishlist'), options={})
  url = {:controller => 'wishlist', :action => 'add_product', :id => product.id}
  button_to(name, url, { :id => 'add_to_wishlist' }.merge(options))
end

#display_wishlist(wishlist, static = false, mini = false) ⇒ Object

Display a wishlist

Parameters

  • wishlist a Wishlist object

  • static add action’s buttons for edit this wishlist if true, false by default



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/wishlist_helper.rb', line 63

def display_wishlist(wishlist, static=false, mini=false)
  content = '<div class="wishlist'+(mini ? ' mini' : '')+'" id="forgeos_commerce_wishlist">'
    content += "<div class='wishlist_name'>#{I18n.t('name').capitalize}</div>"
    content += "<div class='wishlist_name'>#{I18n.t('quantity', :count=>1).capitalize}</div>"
  unless mini
    content += "<div class='wishlist_name'>#{I18n.t('unit_price').capitalize}</div>"
    content += "<div class='wishlist_name'>#{I18n.t('tax', :count=>1).capitalize}</div>"
    content += "<div class='wishlist_name'>#{I18n.t('total').capitalize}</div>"
  end
    content += "<div id='forgeos_commerce_wishlist_products'>"
      content += display_wishlist_all_products_lines(wishlist, static, mini)
    content += "</div>"
  content += "</div>"
  if mini && !wishlist.is_empty?
    content += '<div class="link_empty">'
    content += link_to_wishlist_empty(mini)
    content += '</div>'
    content += '<div class="link_send">'
    content += link_to_send_wishlist(mini)
    content += '</div>'
  end
  content += "<div class='clear'></div>"
end

#display_wishlist_all_products_lines(wishlist, static = false, mini = false) ⇒ Object

Display all products lines

Parameters

  • wishlist a Wishlist object

  • static add action’s buttons for edit this wishlist if true, false by default



46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/wishlist_helper.rb', line 46

def display_wishlist_all_products_lines(wishlist, static=false, mini=false)
  return I18n.t('your_wishlist_is_empty').capitalize if wishlist.nil? || wishlist.is_empty?
  content = ""
  wishlist.products_wishlists.each do |wishlists_product|
    content += display_wishlist_by_wishlists_product(wishlist, wishlists_product, static, mini)
  end
  content += "<div class='wishlist_total'><b>#{I18n.t('total').capitalize} : </b>"
    content += wishlist.total(true).to_s + " " + current_currency.html
  content += "</div>"
end

#display_wishlist_by_wishlists_product(wishlist, wishlists_product, static = false, mini = false) ⇒ Object

Display a wishlist’s product

Parameters

  • wishlist a Wishlist object

  • wishlists_product a WishlistsProduct object

  • static add action’s buttons for edit this wishlist if true, false by default



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/wishlist_helper.rb', line 9

def display_wishlist_by_wishlists_product(wishlist, wishlists_product, static=false, mini=false)
  content = "<div class='wishlist_product_line' id='forgeos_commerce_wishlist_product_line_#{wishlists_product.product_id}'>"
    content += "<div class='wishlist_name'>"
      content += link_to_product(wishlists_product.product)
    content += "</div>"
    content += "<div class='wishlist_quantity'>"
      if static
        content += wishlists_product.quantity.to_s
      else
        content += text_field_tag "wishlist_quantity_#{wishlists_product.product_id}", wishlists_product.quantity.to_s, :size => 2
        content += observe_field("wishlist_quantity_#{wishlists_product.product_id}", :frequency => 1, :loading => "$('#spinner2').show()", :complete => "$('#spinner2').hide()", :url => { :controller => 'wishlist', :action => 'update_quantity', :mini => mini }, :with => "'quantity=' + escape(value) + '&product_id=#{wishlists_product.product_id}'")
      end
    content += "</div>"
    unless mini
      content += "<div class='wishlist_price'>"
        content += wishlists_product.product.price.to_s
      content += "</div>"
      content += "<div class='wishlist_tax'>"
        content += wishlists_product.tax.to_s
      content += "</div>"
      content += "<div class='wishlist_price'>"
        content += wishlists_product.total(wishlists_product.product).to_s + " " + current_currency.html
      content += "</div>"
    end
    content += "<div class='wishlist_remove'>"
      unless static
        content += link_to_wishlist_remove_product(wishlists_product.product, mini)
      end
    content += "</div>"
  content += "</div>"
end


130
131
132
133
134
135
136
# File 'app/helpers/wishlist_helper.rb', line 130

def link_to_send_wishlist(mini=false,name=I18n.t('wishlist.send.friend').capitalize, url={:controller => 'wishlist', :action => 'send_to_friend'}, options={})
  if mini
    link_to_remote name.capitalize, { :method => :get, :update => 'wishlist', :url => url }.merge(options)
  else
    link_to name.capitalize, url, options
  end
end

Extension of link_to(name, options = {}, html_options = nil)

Parameters

  • :name - name, “Wishlist” by default

  • :url - url, => ‘wishlist’ by default

  • options the html options



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

def link_to_wishlist(name=I18n.t('wishlist',:count => 1), url={:controller => 'wishlist'}, options=nil)
  wishlist = Wishlist.find_by_id(session[:wishlist_id])
  unless wishlist.nil?
    name = "#{name} (#{wishlist.size} #{I18n.t('product', :count => wishlist.size)})"
  end
  link_to name.capitalize, {:controller => 'wishlist'}, options
end

Extension of link_to(name, options = {}, html_options = nil)

Parameters

  • :name - name

  • :url - url, => ‘wishlist’, :action => ‘empty’ by default

  • options the html options



108
109
110
111
112
113
114
# File 'app/helpers/wishlist_helper.rb', line 108

def link_to_wishlist_empty(mini=false,name=I18n.t('empty_wishlist').capitalize, url={:controller => 'wishlist', :action => 'empty'}, options={:confirm => I18n.t(:confirm_empty_wishlist)})
  if mini
    link_to_remote name, { :update => 'wishlist', :url => url }.merge(options)
  else
    link_to name, url, options
  end
end

Extension of link_to(name, options = {}, html_options = nil) with a Product object of first parameter

Parameters

  • :product - a Product object

  • :name - name, image_tag(‘forgeos_commerce/remove_product.gif’) by default

  • :url - url, => ‘wishlist’, :action => ‘empty’ by default

  • options the html options



94
95
96
97
98
99
100
# File 'app/helpers/wishlist_helper.rb', line 94

def link_to_wishlist_remove_product(product, mini=false, name=image_tag('forgeos_commerce/remove_product.gif'), options={:confirm => I18n.t(:confirm_remove_product)})
  if mini
    link_to_remote(name,{ :url=>{:controller => 'wishlist', :action => 'remove_product', :id => product}, :update => 'wishlist' }.merge(options))
  else
    link_to(name, {:controller => 'wishlist', :action => 'remove_product', :id => product}, options)
  end
end