module CabooseStore
module ProductsHelper
def category_options(top_categories, selected_id = nil)
arr = []
top_categories.each do |cat|
category_options_helper(cat, selected_id, arr)
end
return arr.join("\n")
end
def category_options_helper(cat, selected_id, arr, prefix = "")
opt = ""
arr << opt
cat.children.each do |cat2|
category_options_helper(cat2, selected_id, arr, "#{prefix} - ")
end
end
def category_checkboxes(top_categories, selected_ids = nil)
str = "
"
top_categories.each do |cat|
category_checkboxes_helper(cat, selected_ids, str)
end
str << "
"
return str
end
def category_checkboxes_helper(cat, selected_ids, str, prefix = "")
str << ""
if cat.children && cat.children.count > 0
str << " "
else
str << " "
end
cat.children.each do |cat2|
str << ""
category_checkboxes_helper(cat2, selected_ids, str, "#{prefix} ")
str << "
"
end
str << ""
end
def product_price(p)
price = ""
if p.price_varies
arr = p.price_range
min = number_to_currency(arr[0], :precision => 2)
max = number_to_currency(arr[1], :precision => 2)
if min.eql? max
price = "#{min}"
else
price = "#{min}-#{max}"
end
else
price = p.variants[0].price
price = number_to_currency(price, :precision => 2)
end
return price
end
def breadcrumb(p)
return p.category.ancestry.collect{|cat| "#{cat.name}"}.join("/")
end
#def product_thumb(product, price)
# style = square_image(product.featured_image)
# price = product.most_popular_variant.price if price.nil?
#
# str = ""
# str << ""
# str << "