Module: Gemgento::ApplicationHelper

Defined in:
app/helpers/gemgento/application_helper.rb

Instance Method Summary collapse

Instance Method Details

Get a breadcrumb trail from root to current category, not including root.

Parameters:

  • category (Gemgento::Category)
  • separator (String) (defaults to: '/')
  • link_options (Hash) (defaults to: {})

    options hash for link_to



111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/helpers/gemgento/application_helper.rb', line 111

def breadcrumbs(category, separator = '/', link_options = {})
  breadcrumbs = ''
  trail = category.heirarchy
  trail << category

  trail.each do |parent|
    breadcrumbs += " #{separator} " unless breadcrumbs.blank? # don't add separator to first link
    breadcrumbs += link_to(parent.name, category_path(parent), link_options)
  end

  return breadcrumbs
end

#current_categoryObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/gemgento/application_helper.rb', line 24

def current_category
  @current_category ||= begin
    if @category
      @category

    elsif @product
      @product.current_category

    else
      Gemgento::Category.root
    end
  end
end

#current_quoteObject



18
19
20
21
22
# File 'app/helpers/gemgento/application_helper.rb', line 18

def current_quote
  @current_quote ||= Quote.current(current_store, session[:quote], current_user) if @current_quote.nil?
  session[:quote] = @current_quote.id
  return @current_quote
end

#current_storeObject



8
9
10
11
12
13
14
15
16
# File 'app/helpers/gemgento/application_helper.rb', line 8

def current_store
  @current_store ||= begin
    if session[:store_id].nil?
      Store.current
    else
      Store.find(session[:store_id])
    end
  end
end

#json_optionsObject



66
67
68
69
70
71
72
# File 'app/helpers/gemgento/application_helper.rb', line 66

def json_options
  @json_options ||= {
      include_products: params[:include_products] ||= false,
      include_simple_products: params[:include_simple_products] ||= false,
      active: params[:active] ||= true
  }
end

Determine if a given category is the current category or a child.

Parameters:

Returns:

  • (Boolean)


46
47
48
# File 'app/helpers/gemgento/application_helper.rb', line 46

def nav_category_is_active(c)
  @curent_category == c or @current_category.children.include?(c)
end

#not_foundObject

Raises:

  • (ActiveRecord::RecordNotFound)


38
39
40
# File 'app/helpers/gemgento/application_helper.rb', line 38

def not_found
  raise ActiveRecord::RecordNotFound
end

#product_asset(product, asset_type_code) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/gemgento/application_helper.rb', line 74

def product_asset(product, asset_type_code)
  asset = Gemgento::Asset.find_by_code(product, asset_type_code)

  if asset.nil? && product.magento_type == 'simple' && product.configurable_products.active.any? # check the configurable if the simple doesn't have images.
    asset = Gemgento::Asset.find_by_code(product.configurable_products.active.first, asset_type_code)
  elsif asset.nil?
    asset = product.assets.first.image
  end

  return asset
end

#product_on_sale?(product, quantity = 1.0) ⇒ Boolean

Determine if a product is on sale in the given session.

Parameters:

Returns:

  • (Boolean)


101
102
103
104
# File 'app/helpers/gemgento/application_helper.rb', line 101

def product_on_sale?(product, quantity = 1.0)
  user_group = current_user ? current_user.user_group : nil
  product.magento_type != 'giftvoucher' && product.on_sale?(user_group, current_store, quantity)
end

#product_price(product, quantity = 1.0) ⇒ BigDecimal

Get the product price for the given session

Parameters:

Returns:

  • (BigDecimal)


91
92
93
94
# File 'app/helpers/gemgento/application_helper.rb', line 91

def product_price(product, quantity = 1.0)
  user_group = current_user ? current_user.user_group : nil
  product.price(user_group, current_store, quantity)
end

#set_layout(html_layout = nil, pjax_layout = false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/gemgento/application_helper.rb', line 50

def set_layout(html_layout = nil, pjax_layout = false)
  html_layout = Config[:layout] if html_layout.nil?

  if request.url # Check if we are redirected
    response.headers['X-PJAX-URL'] = request.url
  end

  if request.headers['X-PJAX']
    pjax_layout
  elsif request.format == 'json'
    false
  else
    html_layout
  end
end

#set_storeObject



4
5
6
# File 'app/helpers/gemgento/application_helper.rb', line 4

def set_store
  session[:store_id] = Store.current.id if session[:store_id].nil?
end