Module: CartHelper

Defined in:
app/helpers/cart_helper.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

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

Parameters

  • :product - a Product object

  • :name - name, <i>

  • :url - url, => ‘cart’, :action => ‘add_product’ by default

  • options the html options



37
38
39
# File 'app/helpers/cart_helper.rb', line 37

def link_to_add_cart(product, name='add_to_cart', url={:controller => 'cart', :action => 'add_product'}, options=nil)
  link_to I18n.t(name).capitalize, url.merge({:id => product.id}), options
end

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

Parameters

  • :name - name, “Cart” by default

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

  • options the html options



23
24
25
26
27
28
# File 'app/helpers/cart_helper.rb', line 23

def link_to_cart(name=I18n.t('cart', :count => 1), url={:controller => 'cart'}, options=nil)
  #unless cart.nil?
  #  name = "#{name} (#{cart.size} #{I18n.t('product', :count => cart.size)})"
  #end
  link_to name.capitalize, {:controller => 'cart'}, options
end

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

Parameters

  • :name - name

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

  • options the html options



9
10
11
12
13
14
15
# File 'app/helpers/cart_helper.rb', line 9

def link_to_cart_empty(mini=false,name=I18n.t('empty_cart').capitalize, url={:controller => 'cart', :action => 'empty'}, options={:confirm => I18n.t(:confirm_empty_cart)})
  if mini
    link_to_remote name, { :update => 'cart', :url => url }.merge(options)
  else
    link_to name, url, options
  end
end