Class: Shop::Tags::Helpers
- Inherits:
-
Object
- Object
- Shop::Tags::Helpers
- Extended by:
- ActionView::Helpers::NumberHelper
- Defined in:
- lib/shop/tags/helpers.rb
Class Method Summary collapse
- .currency(number, attr = {}) ⇒ Object
-
.current_address(tag, of_type = 'billing') ⇒ Object
Return the current address for the current order of_type = the address type (billing|shipping).
- .current_categories(tag) ⇒ Object
- .current_category(tag) ⇒ Object
- .current_image(tag) ⇒ Object
- .current_line_item(tag) ⇒ Object
- .current_line_items(tag) ⇒ Object
- .current_order(tag) ⇒ Object
- .current_product(tag) ⇒ Object
- .current_products(tag) ⇒ Object
Class Method Details
.currency(number, attr = {}) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/shop/tags/helpers.rb', line 225 def currency(number,attr = {}) precision = attr[:precision].present? ? attr[:precision] : Radiant::Config['shop.price_precision'] unit = attr[:unit].present? ? attr[:unit] : Radiant::Config['shop.price_unit'] separator = attr[:separator].present? ? attr[:separator] : Radiant::Config['shop.price_separator'] delimiter = attr[:delimiter].present? ? attr[:delimiter] : Radiant::Config['shop.price_delimiter'] number_to_currency(number.to_f, { :precision => precision.to_i, :unit => unit, :separator => separator, :delimiter => delimiter }) end |
.current_address(tag, of_type = 'billing') ⇒ Object
Return the current address for the current order of_type = the address type (billing|shipping)
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/shop/tags/helpers.rb', line 198 def current_address(tag,of_type = 'billing') if tag.locals.send(of_type).present? return tag.locals.send(of_type) end if tag.locals.shop_order.present? begin # Get the address type (order.billing) address = tag.locals.shop_order.send(of_type) return address unless address.nil? rescue nil end end if user = Users::Tags::Helpers.current_user(tag) begin address = user.send(of_type) return address unless address.nil? rescue nil end end nil end |
.current_categories(tag) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shop/tags/helpers.rb', line 7 def current_categories(tag) result = [] # Returns categories based on the slug of their categories parent page if tag.attr['parent'] result = ShopCategory.all( :joins => 'JOIN pages AS page ON page.id = shop_categories.page_id JOIN pages AS parent ON page.parent_id = parent.id', :conditions => [ 'parent.slug = ?', tag.attr['parent'] ] ) # Returns the current categories if they exist elsif tag.locals.shop_categories.present? result = tag.locals.shop_categories # Page params are protected, send is used to overcome this # elsif tag.locals.page.send(:params).has_key? 'query' # result = ShopCategory.search(tag.locals.page.send(:params)['query']) # Returns all Categories else result = ShopCategory.all end result end |
.current_category(tag) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/shop/tags/helpers.rb', line 34 def current_category(tag) result = nil # Returns a category based on its name (page title) if tag.attr['name'] result = ShopCategory.first( :joins => :page, :conditions => [ "pages.title = ?", tag.attr['name'] ] ) # Returns a category based on its handle (page slug) elsif tag.attr['handle'] result = ShopCategory.first( :joins => :page, :conditions => [ "pages.slug = ?", tag.attr['handle'] ] ) # Returns the current shop_category elsif tag.locals.shop_category.present? result = tag.locals.shop_category # Returns the category of the current shop_product elsif tag.locals.shop_product.present? result = tag.locals.shop_product.category elsif tag.locals.page.shop_category.present? result = tag.locals.page.shop_category elsif tag.locals.page.shop_product.present? result = tag.locals.page.shop_product.category end result end |
.current_image(tag) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/shop/tags/helpers.rb', line 132 def current_image(tag) result = nil if tag.attr['position'] result = tag.locals.images.find_by_position(tag.attr['position'].to_i) elsif tag.locals.image.present? result = tag.locals.image.image rescue tag.locals.image end result end |
.current_line_item(tag) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/shop/tags/helpers.rb', line 182 def current_line_item(tag) result = nil if tag.locals.shop_line_item.present? result = tag.locals.shop_line_item elsif tag.locals.shop_order.present? and tag.locals.shop_product.present? result = tag.locals.shop_order.line_items.find_by_item_id(tag.locals.shop_product.id) end result end |
.current_line_items(tag) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/shop/tags/helpers.rb', line 170 def current_line_items(tag) result = nil if tag.locals.shop_line_items.present? result = tag.locals.shop_line_items else result = tag.locals.shop_order.line_items end result end |
.current_order(tag) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/shop/tags/helpers.rb', line 146 def current_order(tag) result = nil begin if tag.attr['key'] and tag.attr['value'] result = ShopOrder.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] }) elsif tag.locals.shop_order.present? result = tag.locals.shop_order elsif tag.locals.page.request.session[:shop_order].present? session = tag.locals.page.request.session[:shop_order] result = ShopOrder.find(session) elsif tag.locals.response.present? and tag.locals.response.result[:checkout].present? result = ShopOrder.find(tag.locals.response.result[:checkout][:order]) end rescue result = nil end result end |
.current_product(tag) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/shop/tags/helpers.rb', line 96 def current_product(tag) result = nil # Returns a product based on its name (page title) if tag.attr['name'] result = ShopProduct.first( :joins => :page, :conditions => [ "pages.title = ?", tag.attr['name'] ] ) # Returns a product based on its sku (page slug) elsif tag.attr['sku'] result = ShopProduct.first( :joins => :page, :conditions => [ "pages.slug = ?", tag.attr['sku'] ] ) elsif tag.locals.shop_product.present? result = tag.locals.shop_product elsif tag.attr['position'] children = tag.locals.shop_category.page.children result = children.first(:conditions => { :class_name => 'ShopProductPage', :position => tag.attr['position'].to_i }) || children.first(:conditions => {:class_name => 'ShopProductPage'}) result = result.shop_product elsif tag.locals.shop_line_item.present? and tag.locals.shop_line_item.item_type === 'ShopProduct' result = tag.locals.shop_line_item.item elsif tag.locals.page.shop_product.present? result = tag.locals.page.shop_product end result end |
.current_products(tag) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/shop/tags/helpers.rb', line 70 def current_products(tag) result = nil if tag.attr['category'] result = ShopCategory.first( :joins => :page, :conditions => [ 'pages.slug = ?', tag.attr['category'] ] ).products elsif tag.locals.shop_products.present? result = tag.locals.shop_products elsif tag.locals.shop_category.present? result = tag.locals.shop_category.products elsif tag.locals.page.shop_category.present? result = tag.locals.page.shop_category.products else result = ShopProduct.all end result end |