module ProductHelper
def display_catalog(products)
total = (products.is_a?(WillPaginate::Collection)) ? products.total_entries : products.size
content = pluralize total, "result"
products.in_groups_of(4).each do |products_|
products_.each do |product|
content += display_product(product) if product
end
content += '
'
end
content += will_paginate(products).to_s if products.is_a?(WillPaginate::Collection)
return content
end
def display_all_products(products=Product.find_all_by_active_and_deleted(true,false), with_description=false)
content = ''
products.each do |product|
content << display_product(product, with_description)
end
content_tag :div, content, :class=>'products'
end
def display_product(product, with_description=false, options={})
#return I18n.t('no_product') unless product
if product
content = ""
if product.attachments.find_all_by_type('Picture').first
content += "
"
content += image_tag(product.attachments.find_all_by_type('Picture').first.public_filename(options[:thumbnail_type] || :thumb))
content += "
"
end
content += "
"
content += link_to_product product
content += "
"
content += "
"
content += product.price_to_s(true)
#content += product.price.to_s
content += "
"
content += "
"
content += link_to_add_cart(product)
content += "
"
if with_description
content += "
"
content += product.description
content += "
"
end
content += "
"
content += draggable_element("product_#{product.id}", :helper => '"clone"')
end
end
def display_product_page(product)
content = ''
content += '
'
content += '
'
content += '
'
content += "
"
content += product.name
content += "
"
content += ''
content += '
'
content += '
'
content += '
'
content += product.description
content += '
'
content += '
'
product.pictures.each do |picture|
content += (picture == product.pictures.first ? image_tag(picture.public_filename('')) : image_tag(picture.public_filename(:small)))
end
#content += image_tag(product.attachments.find_all_by_type('Picture').first.public_filename(:normal)) unless product.attachments.find_all_by_type('Picture').empty?
content += '
'
content += '
'
content += display_product_page_attributes(product)
content += '
'
content += '
'
content += '
'
content += 'price: '
content += '
'
content += '
'
content += product.price_to_s(true)
content += '
'
content += '
'
content += '
'
content += link_to_add_cart(product)
content += '
'
content += '
'
content += '
'
content += draggable_element("product_#{product.id}", :cursor => '"move"', :helper => "function(event) { return $(''); }" )
end
def display_product_page_attributes(product)
content = ""
return content unless product && product.product_type
product.product_type.product_attributes.each do |attribute|
content += ""
content += attribute.name + " : "
content += "
"
content += ''
attribute.attribute_values.each do |attribute_value|
content += '
'
content += attribute_value.name
content += "
"
end
content += '
'
content += ""
end
content
end
def link_to_product(product, name=nil, options=nil)
name = product.name if name.nil?
link_to name, [:seo,product], options
end
end