Module: Gemgento::ApplicationHelper
- Defined in:
- app/helpers/gemgento/application_helper.rb
Instance Method Summary collapse
-
#breadcrumbs(category, separator = '/', link_options = {}) ⇒ Object
Get a breadcrumb trail from root to current category, not including root.
- #current_category ⇒ Object
- #current_quote ⇒ Object
- #current_store ⇒ Object
- #json_options ⇒ Object
-
#nav_category_is_active(c) ⇒ Boolean
Determine if a given category is the current category or a child.
- #not_found ⇒ Object
- #product_asset(product, asset_type_code) ⇒ Object
-
#product_on_sale?(product, quantity = 1.0) ⇒ Boolean
Determine if a product is on sale in the given session.
-
#product_price(product, quantity = 1.0) ⇒ BigDecimal
Get the product price for the given session.
- #set_layout(html_layout = nil, pjax_layout = false) ⇒ Object
- #set_store ⇒ Object
Instance Method Details
#breadcrumbs(category, separator = '/', link_options = {}) ⇒ Object
Get a breadcrumb trail from root to current category, not including root.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/gemgento/application_helper.rb', line 111 def (category, separator = '/', = {}) = '' trail = category.heirarchy trail << category trail.each do |parent| += " #{separator} " unless .blank? # don't add separator to first link += link_to(parent.name, category_path(parent), ) end return end |
#current_category ⇒ Object
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_quote ⇒ Object
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_store ⇒ Object
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_options ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/helpers/gemgento/application_helper.rb', line 66 def @json_options ||= { include_products: params[:include_products] ||= false, include_simple_products: params[:include_simple_products] ||= false, active: params[:active] ||= true } end |
#nav_category_is_active(c) ⇒ Boolean
Determine if a given category is the current category or a child.
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_found ⇒ Object
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.
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
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 |