diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb index 75e5281..321ec23 100644 --- a/app/controllers/admin/categories_controller.rb +++ b/app/controllers/admin/categories_controller.rb @@ -7,7 +7,6 @@ class CategoriesController < AdminController def index @categories = environment.categories.where("parent_id is null AND type is null") @regions = environment.regions.where(:parent_id => nil) - @product_categories = environment.product_categories.where(:parent_id => nil) end def get_children diff --git a/app/controllers/admin/edit_template_controller.rb b/app/controllers/admin/edit_template_controller.rb index d5f6d02..3a2561c 100644 --- a/app/controllers/admin/edit_template_controller.rb +++ b/app/controllers/admin/edit_template_controller.rb @@ -1,7 +1,7 @@ class EditTemplateController < AdminController - + protect 'edit_environment_design', :environment - + #FIXME #design_editor :holder => 'environment', :autosave => true, :block_types => :block_types @@ -9,7 +9,6 @@ class EditTemplateController < AdminController %w[ FavoriteLinks ListBlock - SellersSearchBlock ] end diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index f5ce5fa..0e03346 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -1,9 +1,9 @@ class EnvironmentDesignController < BoxOrganizerController - + protect 'edit_environment_design', :environment def available_blocks - @available_blocks ||= [ ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + @available_blocks ||= [ ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) end diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 4d5e070..9ae0e3e 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -409,9 +409,6 @@ class CmsController < MyProfileController ] articles += special_article_types if params && params[:cms] parent_id = params ? params[:parent_id] : nil - if profile.enterprise? - articles << EnterpriseHomepage - end if @parent && @parent.blog? articles -= Article.folder_types.map(&:constantize) end diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb deleted file mode 100644 index 6e06d0a..0000000 --- a/app/controllers/my_profile/manage_products_controller.rb +++ /dev/null @@ -1,229 +0,0 @@ -class ManageProductsController < ApplicationController - needs_profile - - protect 'manage_products', :profile, :except => [:show] - before_filter :check_environment_feature - before_filter :login_required, :except => [:show] - before_filter :create_product?, :only => [:new] - - protected - - def check_environment_feature - unless profile.environment.enabled?('products_for_enterprises') - render_not_found - return - end - end - - def create_product? - if !profile.create_product? - render_access_denied - return - end - end - - public - - def index - @products = @profile.products.paginate(:per_page => 10, :page => params[:page]) - end - - def show - @product = @profile.products.find(params[:id]) - @inputs = @product.inputs - @allowed_user = user && user.has_permission?('manage_products', profile) - end - - def categories_for_selection - @category = environment.categories.find_by id: params[:category_id] - @object_name = params[:object_name] - if @category - @categories = @category.children - @level = @category.leaf? ? @category.level : @categories.first.level - else - @categories = ProductCategory.top_level_for(environment) - @level = 0 - end - render :partial => 'categories_for_selection', :locals => { :categories => @categories, :level => @level } - end - - def new - @no_design_blocks = true - @category = params[:selected_category_id] ? Category.find(params[:selected_category_id]) : nil - @product = @profile.products.build(:product_category => @category) - @categories = ProductCategory.top_level_for(environment) - @level = 0 - if request.post? - if @product.save - session[:notice] = _('Product succesfully created') - render :partial => 'shared/redirect_via_javascript', - :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } - else - render_dialog_error_messages 'product' - end - end - end - - def edit - @product = @profile.products.find(params[:id]) - field = params[:field] - if request.post? - begin - @product.update!(params[:product]) - render :partial => "display_#{field}", :locals => {:product => @product} - rescue Exception => e - render :partial => "edit_#{field}", :locals => {:product => @product, :errors => true} - end - else - render :partial => "edit_#{field}", :locals => {:product => @product, :errors => false} - end - end - - def edit_category - @product = @profile.products.find(params[:id]) - @category = @product.product_category || ProductCategory.first - @categories = ProductCategory.top_level_for(environment) - @edit = true - @level = @category.level - if request.post? - if @product.update({:product_category_id => params[:selected_category_id]}, :without_protection => true) - render :partial => 'shared/redirect_via_javascript', - :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } - else - render_dialog_error_messages 'product' - end - end - end - - def show_category_tree - @category = environment.categories.find params[:category_id] - render :partial => 'selected_category_tree' - end - - def search_categories - @term = params[:term].downcase - conditions = ['LOWER(name) LIKE ? OR LOWER(name) LIKE ?', "#{@term}%", "% #{@term}%"] - @categories = ProductCategory.where(conditions).limit(10) - render :json => (@categories.map do |category| - {:label => category.name, :value => category.id} - end) - end - - def add_input - @product = @profile.products.find(params[:id]) - @input = @product.inputs.build - @categories = ProductCategory.top_level_for(environment) - @level = 0 - if request.post? - if @input.update(:product_category_id => params[:selected_category_id]) - @inputs = @product.inputs - render :partial => 'display_inputs' - else - render_dialog_error_messages 'product' - end - else - render :partial => 'add_input' - end - end - - def manage_product_details - @product = @profile.products.find(params[:id]) - if request.post? - @product.update_price_details(params[:price_details]) if params[:price_details] - render :partial => 'display_price_details' - else - render :partial => 'manage_product_details' - end - end - - def remove_price_detail - @product = @profile.products.find(params[:product]) - @price_detail = @product.price_details.find(params[:id]) - @product = @price_detail.product - if request.post? - @price_detail.destroy - render :nothing => true - end - end - - def display_price_composition_bar - @product = @profile.products.find(params[:id]) - render :partial => 'price_composition_bar' - end - - def display_inputs_cost - @product = @profile.products.find(params[:id]) - render :inline => "<%= float_to_currency(@product.inputs_cost) %>" - end - - def destroy - @product = @profile.products.find(params[:id]) - if @product.destroy - session[:notice] = _('Product succesfully removed') - redirect_back_or_default :action => 'index' - else - session[:notice] = _('Could not remove the product') - redirect_back_or_default :action => 'show', :id => @product - end - end - - def edit_input - if request.xhr? - @input = @profile.inputs.find_by id: params[:id] - if @input - if request.post? - if @input.update(params[:input]) - render :partial => 'display_input', :locals => {:input => @input} - else - render :partial => 'edit_input' - end - else - render :partial => 'edit_input' - end - else - render :text => _('The input was not found') - end - end - end - - def order_inputs - @product = @profile.products.find(params[:id]) - @product.order_inputs!(params[:input]) if params[:input] - render :nothing => true - end - - def remove_input - @input = @profile.inputs.find(params[:id]) - @product = @input.product - if request.post? - if @input.destroy - @inputs = @product.inputs - render :partial => 'display_inputs' - else - render_dialog_error_messages 'input' - end - end - end - - def certifiers_for_selection - @qualifier = Qualifier.exists?(:id => params[:id]) ? Qualifier.find(params[:id]) : nil - render :update do |page| - page.replace_html params[:certifier_area], :partial => 'certifiers_for_selection' - end - end - - def create_production_cost - cost = @profile.production_costs.create(:name => params[:id]) - if cost.valid? - cost.save - render :text => {:name => cost.name, - :id => cost.id, - :ok => true - }.to_json - else - render :text => {:ok => false, - :error_msg => _(cost.errors['name'].join('\n')) % {:fn => _('Name')} - }.to_json - end - end -end diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 08e0554..a0c1481 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -45,17 +45,10 @@ class ProfileDesignController < BoxOrganizerController if profile.enterprise? blocks << DisabledEnterpriseMessageBlock blocks << HighlightsBlock - blocks << ProductCategoriesBlock - blocks << FeaturedProductsBlock blocks << FansBlock blocks += plugins.dispatch(:extra_blocks, :type => Enterprise) end - # product block exclusive for enterprises in environments that permits it - if profile.enterprise? && profile.environment.enabled?('products_for_enterprises') - blocks << ProductsBlock - end - # block exclusive to profiles that have blog if profile.has_blog? blocks << BlogArchivesBlock diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb deleted file mode 100644 index 25e4879..0000000 --- a/app/controllers/public/catalog_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -class CatalogController < PublicController - needs_profile - - before_filter :check_enterprise_and_environment - - def index - extend CatalogHelper - catalog_load_index - end - - protected - - def check_enterprise_and_environment - unless profile.enterprise? && @profile.environment.enabled?('products_for_enterprises') - redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index' - end - end - -end diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 1718518..ed70791 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -52,7 +52,6 @@ class SearchController < PublicController [ [ :people, _('People'), :recent_people ], [ :enterprises, _('Enterprises'), :recent_enterprises ], - [ :products, _('Products'), :recent_products ], [ :events, _('Upcoming events'), :upcoming_events ], [ :communities, _('Communities'), :recent_communities ], [ :articles, _('Contents'), :recent_articles ] @@ -78,16 +77,17 @@ class SearchController < PublicController full_text_search end - def products - @scope = @environment.products - full_text_search - end - def enterprises @scope = visible_profiles(Enterprise) full_text_search end + # keep URL compatibility + def products + return render_not_found unless defined? ProductsPlugin + redirect_to url_for(params.merge controller: 'products_plugin/search', action: :products) + end + def communities @scope = visible_profiles(Community) full_text_search @@ -186,7 +186,6 @@ class SearchController < PublicController people: _('People'), communities: _('Communities'), enterprises: _('Enterprises'), - products: _('Products and Services'), events: _('Events'), } end @@ -260,12 +259,11 @@ class SearchController < PublicController end def available_assets - assets = { + { articles: _('Contents'), enterprises: _('Enterprises'), people: _('People'), communities: _('Communities'), - products: _('Products and Services'), } end diff --git a/app/helpers/action_tracker_helper.rb b/app/helpers/action_tracker_helper.rb index dbd0902..ef21767 100644 --- a/app/helpers/action_tracker_helper.rb +++ b/app/helpers/action_tracker_helper.rb @@ -67,24 +67,6 @@ module ActionTrackerHelper } end - def create_product_description ta - _('created the product %{title}') % { - title: link_to(truncate(ta.get_name), ta.get_url), - } - end - - def update_product_description ta - _('updated the product %{title}') % { - title: link_to(truncate(ta.get_name), ta.get_url), - } - end - - def remove_product_description ta - _('removed the product %{title}') % { - title: truncate(ta.get_name), - } - end - def favorite_enterprise_description ta _('favorited enterprise %{title}') % { title: link_to(truncate(ta.get_enterprise_name), ta.get_enterprise_url), diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 71cad88..2006661 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -44,8 +44,6 @@ module ApplicationHelper include TokenHelper - include CatalogHelper - include PluginsHelper include ButtonsHelper @@ -787,7 +785,7 @@ module ApplicationHelper return "" if categories.blank? content_tag(:ul) do categories.map do |category| - category_path = category.kind_of?(ProductCategory) ? {:controller => 'search', :action => 'assets', :asset => 'products', :product_category => category.id} : { :controller => 'search', :action => 'category_index', :category_path => category.explode_path } + category_path = { :controller => 'search', :action => 'category_index', :category_path => category.explode_path } if category.display_in_menu? content_tag(:li) do if !category.is_leaf_displayable_in_menu? diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb deleted file mode 100644 index 6adc0a9..0000000 --- a/app/helpers/catalog_helper.rb +++ /dev/null @@ -1,45 +0,0 @@ -module CatalogHelper - - include DisplayHelper - include ManageProductsHelper - - def catalog_load_index options = {:page => params[:page], :show_categories => true} - if options[:show_categories] - @category = params[:level] ? ProductCategory.find(params[:level]) : nil - @categories = ProductCategory.on_level(params[:level]).order(:name) - end - - @products = profile.products.from_category(@category). - reorder('available desc, highlighted desc, name asc'). - paginate(:per_page => @profile.products_per_catalog_page, :page => options[:page]) - end - - def breadcrumb(category) - start = link_to(_('Start'), {:controller => :catalog, :action => 'index'}) - ancestors = category.ancestors.map { |c| link_to(c.name, {:controller => :catalog, :action => 'index', :level => c.id}) }.reverse - current_level = content_tag('strong', category.name) - all_items = [start] + ancestors + [current_level] - content_tag('div', safe_join(all_items, ' → '), :id => 'breadcrumb') - end - - def category_link(category) - count = profile.products.from_category(category).count - name = truncate(category.name, :length => 22 - count.to_s.size) - link = link_to(name, {:controller => 'catalog', :action => 'index', :level => category.id}, :title => category.name) - content_tag('div', "#{link} #{count}".html_safe) if count > 0 - end - - def category_with_sub_list(category) - content_tag 'li', "#{category_link(category)}\n#{sub_category_list(category)}".html_safe - end - - def sub_category_list(category) - sub_categories = [] - category.children.order(:name).each do |sub_category| - cat_link = category_link sub_category - sub_categories << content_tag('li', cat_link) unless cat_link.nil? - end - content_tag('ul', sub_categories.join.html_safe) if sub_categories.size > 0 - end - -end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index 8a47344..748bc81 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -2,7 +2,6 @@ module CategoriesHelper TYPES = [ [ _('General Category'), Category.to_s ], - [ _('Product Category'), ProductCategory.to_s ], [ _('Region'), Region.to_s ], ] diff --git a/app/helpers/display_helper.rb b/app/helpers/display_helper.rb index 97f3054..71eddb9 100644 --- a/app/helpers/display_helper.rb +++ b/app/helpers/display_helper.rb @@ -1,13 +1,5 @@ module DisplayHelper - def link_to_product(product, opts={}) - return _('No product') unless product - target = product_path(product) - link_to content_tag( 'span', product.name ), - target, - opts - end - def themed_path(file) if File.exists?(File.join(Rails.root, 'public', theme_path, file)) File.join(theme_path, file) @@ -16,42 +8,21 @@ module DisplayHelper end end - def image_link_to_product(product, opts={}) - return _('No product') unless product - target = product_path(product) - link_to image_tag(product.default_image(:big), :alt => product.name), - target, - opts - end - def price_span(price, options = {}) content_tag 'span', number_to_currency(price, :unit => environment.currency_unit, :delimiter => environment.currency_delimiter, :separator => environment.currency_separator), options end - def product_path(product) - product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product) : product.enterprise.url - end - def link_to_tag(tag, html_options = {}) link_to tag.name, {:controller => 'search', :action => 'tag', :tag => tag.name}, html_options end def link_to_category(category, full = true, html_options = {}) - return _('Uncategorized product') unless category name = full ? category.full_name(' → ') : category.name link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname }), html_options end - def link_to_product_category(category) - if category - link_to(category.name, :controller => 'search', :action => 'products', :category_path => category.explode_path) - else - _('Uncategorized product') - end - end - def txt2html(txt) ret = txt.strip. gsub( /\s*\n\s*\n\s*/, "\r

\r" ). diff --git a/app/helpers/enterprise_homepage_helper.rb b/app/helpers/enterprise_homepage_helper.rb deleted file mode 100644 index d0acffd..0000000 --- a/app/helpers/enterprise_homepage_helper.rb +++ /dev/null @@ -1,25 +0,0 @@ -module EnterpriseHomepageHelper - - def display_profile_info(profile) - data = '' - [ - [ _('Contact person:'), :contact_person ], - [ _('e-Mail:'), :contact_email ], - [ _('Phone(s):'), :contact_phone ], - [ _('Location:'), :location ], - [ _('Address:'), :address ], - [ _('Economic activity:'), :economic_activity ] - ].each { | name, att | - if profile.send( att ) and not profile.send( att ).blank? - data << content_tag( 'li', content_tag('strong', name) +' '+ profile.send( att ).to_s ) +"\n" - end - } - if profile.respond_to?(:distance) and !profile.distance.nil? - data << content_tag( 'li', - content_tag('strong',_('Distance:')) +' '+ - "%.2f%" % profile.distance - ) + "\n" - end - content_tag('div', content_tag('ul', data), :class => 'enterprise-info') - end -end diff --git a/app/helpers/manage_products_helper.rb b/app/helpers/manage_products_helper.rb deleted file mode 100644 index 9e44e86..0000000 --- a/app/helpers/manage_products_helper.rb +++ /dev/null @@ -1,289 +0,0 @@ -# encoding: UTF-8 - -module ManageProductsHelper - - def remote_function_to_update_categories_selection(container_id, options = {}) - remote_function({ - :update => container_id, - :url => { :action => "categories_for_selection" }, - :loading => "loading('hierarchy_navigation', '#{ _('loading…') }'); loading('#{container_id}', ' ')", - :complete => "loading_done('hierarchy_navigation'); loading_done('#{container_id}')" - }.merge(options)) - end - - def hierarchy_category_item(category, make_links, title = nil) - title ||= category.name - if make_links - link_to(title, '#', - :title => title, - :onclick => remote_function_to_update_categories_selection("categories_container_level#{ category.level + 1 }", - :with => "'category_id=#{ category.id }'" - ) - ) - else - title - end - end - - def hierarchy_category_navigation(current_category, options = {}) - hierarchy = [] - if current_category - hierarchy << current_category.name unless options[:hide_current_category] - ancestors = current_category.ancestors - ancestors.each do |category| - hierarchy << hierarchy_category_item(category, options[:make_links]) - end - end - hierarchy.reverse.join(options[:separator] || ' → ') - end - - def options_for_select_categories(categories, selected = nil) - safe_join(categories.sort_by{ |cat| - cat.name.transliterate}.map do |category| - selected_attribute = selected.nil? ? '' : (category == selected ? "selected='selected'" : '') - "".html_safe - end, "\n") - end - - def build_selects_for_ancestors(ancestors, current_category) - current_ancestor = ancestors.shift - if current_ancestor.nil? - select_for_new_category(current_category.children, current_category.level + 1) - else - content_tag('div', - select_tag('category_id', - options_for_select_categories(current_ancestor.siblings + [current_ancestor], current_ancestor), - :size => 10, - :onchange => remote_function_to_update_categories_selection("categories_container_level#{ current_ancestor.level + 1 }", :with => "'category_id=' + this.value") - ) + - build_selects_for_ancestors(ancestors, current_category), - :class => 'categories_container', - :id => "categories_container_level#{ current_ancestor.level }" - ) - end - end - - def selects_for_all_ancestors(current_category) - build_selects_for_ancestors(current_category.ancestors.reverse + [current_category], current_category) - end - - def select_for_new_category(categories, level) - content_tag('div', - render(:partial => 'categories_for_selection', :locals => { :categories => categories, :level => level }), - :class => 'categories_container', - :id => "categories_container_level#{ level }" - ) - end - - def categories_container(categories_selection_html, hierarchy_html = '') - content_tag 'div', - safe_join( - [ - render('categories_autocomplete'), - hidden_field_tag('selected_category_id'), - content_tag('div', hierarchy_html, :id => 'hierarchy_navigation'), - content_tag('div', categories_selection_html, :id => 'categories_container_wrapper') - ], ''), - :id => 'categories-container' - end - - def select_for_categories(categories, level = 0) - if categories.empty? - content_tag('div', '', :id => 'no_subcategories') - else - select_tag('category_id', - options_for_select_categories(categories), - :size => 10, - :onchange => remote_function_to_update_categories_selection("categories_container_level#{ level + 1 }", :with => "'category_id=' + this.value") - ) + - content_tag('div', '', :class => 'categories_container', :id => "categories_container_level#{ level + 1 }") - end - end - - def edit_link(label, url, html_options = {}) - return '' unless (user && user.has_permission?('manage_products', profile)) - link_to(label, url, html_options) - end - - def edit_product_link_to_remote(product, field, label, html_options = {}) - return '' unless (user && user.has_permission?('manage_products', profile)) - options = html_options.merge(:id => 'link-edit-product-' + field) - options[:class] = options[:class] ? options[:class] + ' link-to-remote' : 'link-to-remote' - - link_to_remote(label, - {:update => "product-#{field}", - :url => { :controller => 'manage_products', :action => "edit", :id => product.id, :field => field }, - :method => :get, - :loading => "loading_for_button('#link-edit-product-#{field}')"}, - options) - end - - def edit_button(type, label, url, html_options = {}) - return '' unless (user && user.has_permission?('manage_products', profile)) - button(type, label, url, html_options) - end - - def edit_product_button_to_remote(product, field, label, html_options = {}) - the_class = 'button with-text icon-edit' - if html_options.has_key?(:class) - the_class << ' ' << html_options[:class] - end - edit_product_link_to_remote(product, field, label, html_options.merge(:class => the_class)) - end - - def edit_ui_button(label, url, html_options = {}) - return '' unless (user && user.has_permission?('manage_products', profile)) - ui_button(label, url, html_options) - end - - def edit_product_ui_button_to_remote(product, field, label, html_options = {}) - return '' unless (user && user.has_permission?('manage_products', profile)) - id = 'edit-product-remote-button-ui-' + field - options = html_options.merge(:id => id) - - ui_button_to_remote(label, - {:update => "product-#{field}", - :url => { :controller => 'manage_products', :action => "edit", :id => product.id, :field => field }, - :complete => "jQuery('#edit-product-button-ui-#{field}').hide()", - :method => :get, - :loading => "loading_for_button('##{id}')"}, - options) - end - - def cancel_edit_product_link(product, field, html_options = {}) - return '' unless (user && user.has_permission?('manage_products', profile)) - button_to_function(:cancel, _('Cancel'), nil, html_options) do |page| - page.replace_html "product-#{field}", CGI::escapeHTML(render :partial => "display_#{field}", :locals => {:product => product}) - end - end - - def edit_product_category_link(product, html_options = {}) - return '' unless (user && user.has_permission?('manage_products', profile)) - options = html_options.merge(:id => 'link-edit-product-category') - link_to(_('Change category'), { :action => 'edit_category', :id => product.id}, options) - end - - def display_value(product) - price = product.price - return '' if price.blank? || price.zero? - discount = product.discount - if discount.blank? || discount.zero? - result = display_price(_('Price: '), price) - else - result = display_price_with_discount(price, product.price_with_discount) - end - content_tag('span', content_tag('span', result, :class => 'product-price'), :class => "#{product.available? ? '' : 'un'}available-product") - end - - def display_availability(product) - if !product.available? - ui_highlight(_('Product not available!')) - end - end - - def display_price(label, price) - content_tag('span', label, :class => 'field-name') + - content_tag('span', float_to_currency(price), :class => 'field-value') - end - - def display_price_with_discount(price, price_with_discount) - original_value = content_tag('span', display_price(_('List price: '), price), :class => 'list-price') - discount_value = content_tag('span', display_price(_('On sale: '), price_with_discount), :class => 'on-sale-price') - original_value + tag('br') + discount_value - end - - def display_qualifiers(product) - data = '' - product.product_qualifiers.each do |pq| - certified_by = '' - certifier = pq.certifier - if certifier - certifier_name = certifier.link.blank? ? certifier.name : link_to(certifier.name, certifier.link) - certified_by = _('certified by %s') % certifier_name - else - certified_by = _('(Self declared)') - end - data << content_tag('li', "✔ #{pq.qualifier.name} #{certified_by}", :class => 'product-qualifiers-item') - end - content_tag('ul', data, :id => 'product-qualifiers') - end - - def qualifiers_for_select - [[_('Select...'), nil]] + environment.qualifiers.sort.map{ |c| [c.name, c.id] } - end - def certifiers_for_select(qualifier) - [[_('Self declared'), nil]] + qualifier.certifiers.sort.map{ |c| [c.name, c.id] } - end - def select_qualifiers(product, selected = nil) - select_tag('selected_qualifier', options_for_select(qualifiers_for_select, selected), - :onchange => remote_function( - :url => {:action => 'certifiers_for_selection'}, - :with => "'id=' + value + '&certifier_area=' + jQuery(this).parent().next().attr('id')", - :before => "small_loading(jQuery(this).parent().next().attr('id'), ' ')" - ), - :id => nil - ) - end - def select_certifiers(qualifier, product = nil) - if qualifier - selected = product ? product.product_qualifiers.find_by(qualifier_id: qualifier.id).certifier_id : nil - select_tag("product[qualifiers_list][#{qualifier.id}]", options_for_select(certifiers_for_select(qualifier), selected)) - else - select_tag("product[qualifiers_list][nil]") - end - end - - def remove_qualifier_button - button_to_function(:delete, content_tag('span', _('Delete qualifier')), "jQuery(this).parents('tr').remove()") - end - - def select_unit(object) - collection_select(object.class.name.downcase, :unit_id, environment.units, :id, :singular, {:include_blank => _('Select the unit')}) - end - - def input_icon(input) - if input.is_from_solidarity_economy? - hint = _('Product from solidarity economy') - image_tag("/images/solidarity-economy.png", :class => 'solidatiry-economy-icon', :alt => hint, :title => hint) - end - end - - def display_price_by(unit) - selected_unit = content_tag('span', unit, :class => 'selected-unit') - content_tag('span', _('by') + ' ' + selected_unit, :class => 'price-by-unit') - end - - def label_amount_used(input) - product_unit = input.product.unit - if product_unit.blank? - _('Amount used in this product or service') - else - _('Amount used by %s of this product or service') % product_unit.singular.downcase - end - end - - def display_unit(input) - input_amount_used = content_tag('span', input.formatted_amount, :class => 'input-amount-used') - return input_amount_used if input.unit.blank? - n_('1 %{singular_unit}', '%{num} %{plural_unit}', input.amount_used.to_f) % { :num => input_amount_used, :singular_unit => content_tag('span', input.unit.singular, :class => 'input-unit'), :plural_unit => content_tag('span', input.unit.plural, :class => 'input-unit') } - end - - def select_production_cost(product,selected=nil) - url = url_for( :controller => 'manage_products', :action => 'create_production_cost' ) - prompt_msg = _('Insert the name of the new cost:') - error_msg = _('Something went wrong. Please, try again') - select_tag('price_details[][production_cost_id]', - '' + - options_for_select(product.available_production_costs.map {|item| [truncate(item.name, {:length => 10, :omission => '...'}), item.id]} + [[_('Other cost'), '']], selected), - {:class => 'production-cost-selection', - :onchange => "productionCostTypeChange(this, '#{url}', '#{prompt_msg}', '#{error_msg}')"}) - end - - def price_composition_progressbar_text(product, args = {}) - currency = environment.currency_unit - production_cost = args[:production_cost_value] || product.formatted_value(:total_production_cost) - product_price = args[:product_price] || product.formatted_value(:price) - - _("%{currency} %{production_cost} of %{currency} %{product_price}") % {:currency => currency, :production_cost => content_tag('span', production_cost, :class => 'production_cost'), :product_price => content_tag('span', product_price, :class => 'product_price')} - end -end diff --git a/app/helpers/profile_image_helper.rb b/app/helpers/profile_image_helper.rb index 15f6410..7889bcb 100644 --- a/app/helpers/profile_image_helper.rb +++ b/app/helpers/profile_image_helper.rb @@ -82,7 +82,6 @@ module ProfileImageHelper ] elsif profile.kind_of?(Enterprise) [ - {_('Products') => {:href => catalog_path(profile.identifier)}}, {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}, diff --git a/app/models/article.rb b/app/models/article.rb index 980397d..1502d11 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -604,7 +604,7 @@ class Article < ApplicationRecord end def accept_category?(cat) - !cat.is_a?(ProductCategory) + true end def public? diff --git a/app/models/box.rb b/app/models/box.rb index 166ca79..a63c03e 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -41,7 +41,6 @@ class Box < ApplicationRecord ProfileImageBlock, RawHTMLBlock, RecentDocumentsBlock, - SellersSearchBlock, TagsBlock ] end @@ -54,21 +53,17 @@ class Box < ApplicationRecord EnterprisesBlock, FansBlock, FavoriteEnterprisesBlock, - FeaturedProductsBlock, FeedReaderBlock, HighlightsBlock, LinkListBlock, LocationBlock, LoginBlock, MyNetworkBlock, - ProductsBlock, - ProductCategoriesBlock, ProfileImageBlock, ProfileInfoBlock, ProfileSearchBlock, RawHTMLBlock, RecentDocumentsBlock, - SellersSearchBlock, SlideshowBlock, TagsBlock ] diff --git a/app/models/category.rb b/app/models/category.rb index 1d113f7..37e859d 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -35,8 +35,6 @@ class Category < ApplicationRecord has_many :people, :through => :profile_categorizations, :source => :profile, :class_name => 'Person' has_many :communities, :through => :profile_categorizations, :source => :profile, :class_name => 'Community' - has_many :products, :through => :enterprises - acts_as_having_image before_save :normalize_display_color @@ -64,10 +62,6 @@ class Category < ApplicationRecord self.communities.reorder('created_at DESC, id DESC').paginate(page: 1, per_page: limit) end - def recent_products(limit = 10) - self.products.reorder('created_at DESC, id DESC').paginate(page: 1, per_page: limit) - end - def recent_articles(limit = 10) self.articles.recent(limit) end diff --git a/app/models/certifier.rb b/app/models/certifier.rb deleted file mode 100644 index a3a119e..0000000 --- a/app/models/certifier.rb +++ /dev/null @@ -1,35 +0,0 @@ -class Certifier < ApplicationRecord - - attr_accessible :name, :environment - - SEARCHABLE_FIELDS = { - :name => {:label => _('Name'), :weight => 10}, - :description => {:label => _('Description'), :weight => 3}, - :link => {:label => _('Link'), :weight => 1}, - } - - belongs_to :environment - - has_many :qualifier_certifiers, :dependent => :destroy - has_many :qualifiers, :through => :qualifier_certifiers - - has_many :product_qualifiers - has_many :products, :through => :product_qualifiers, :source => :product - - validates_presence_of :environment_id - validates_presence_of :name - - def destroy - product_qualifiers.each { |pq| pq.update! :certifier => nil } - super - end - - def link - self[:link] || '' - end - - def <=>(b) - self.name.downcase.transliterate <=> b.name.downcase.transliterate - end - -end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 10e5fcc..bf30e12 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -1,8 +1,7 @@ -# An enterprise is a kind of organization. According to the system concept, -# only enterprises can offer products and services. class Enterprise < Organization - attr_accessible :business_name, :address_reference, :district, :tag_list, :organization_website, :historic_and_current_context, :activities_short_description, :products_per_catalog_page + attr_accessible :business_name, :address_reference, :district, :tag_list, + :organization_website, :historic_and_current_context, :activities_short_description SEARCH_FILTERS = { :order => %w[more_recent more_popular more_active], @@ -17,11 +16,6 @@ class Enterprise < Organization acts_as_trackable after_add: proc{ |p, t| notify_activity t } - has_many :products, :foreign_key => :profile_id, :dependent => :destroy - has_many :product_categories, :through => :products - has_many :inputs, :through => :products - has_many :production_costs, :as => :owner - has_many :favorite_enterprise_people has_many :fans, source: :person, through: :favorite_enterprise_people @@ -29,10 +23,6 @@ class Enterprise < Organization settings_items :organization_website, :historic_and_current_context, :activities_short_description - settings_items :products_per_catalog_page, :type => :integer, :default => 6 - alias_method :products_per_catalog_page_before_type_cast, :products_per_catalog_page - validates_numericality_of :products_per_catalog_page, :allow_nil => true, :greater_than => 0 - extend SetProfileRegionFromCityState::ClassMethods set_profile_region_from_city_state @@ -66,10 +56,6 @@ class Enterprise < Organization environment ? environment.active_enterprise_fields : [] end - def highlighted_products_with_image(options = {}) - Product.where(:highlighted => true).joins(:image) - end - def required_fields environment ? environment.required_enterprise_fields : [] end @@ -136,19 +122,14 @@ class Enterprise < Organization links = [ {:name => _("Enterprises's profile"), :address => '/profile/{profile}', :icon => 'ok'}, {:name => _('Blog'), :address => '/{profile}/blog', :icon => 'edit'}, - {:name => _('Products'), :address => '/catalog/{profile}', :icon => 'new'}, ] blocks = [ [MainBlock.new], [ ProfileImageBlock.new, LinkListBlock.new(:links => links), - ProductCategoriesBlock.new ], [LocationBlock.new] ] - if environment.enabled?('products_for_enterprises') - blocks[2].unshift ProductsBlock.new - end blocks end @@ -189,14 +170,6 @@ class Enterprise < Organization {:title => _('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} end - def create_product? - true - end - - def catalog_url - { :profile => identifier, :controller => 'catalog'} - end - def more_recent_label '' end @@ -205,5 +178,4 @@ class Enterprise < Organization super or self.fans.where(id: person.id).count > 0 end - end diff --git a/app/models/enterprise_homepage.rb b/app/models/enterprise_homepage.rb deleted file mode 100644 index 15f5abf..0000000 --- a/app/models/enterprise_homepage.rb +++ /dev/null @@ -1,42 +0,0 @@ -class EnterpriseHomepage < Article - - def self.type_name - _('Homepage') - end - - def self.short_description - _('Enterprise homepage') - end - - def self.description - _('Display the summary of profile.') - end - - def name - profile.nil? ? _('Homepage') : profile.name - end - - def to_html(options = {}) - enterprise_homepage = self - proc do - extend EnterpriseHomepageHelper - extend CatalogHelper - catalog_load_index :page => 1, :show_categories => false - render :partial => 'content_viewer/enterprise_homepage', :object => enterprise_homepage - end - end - - # disable cache because of products - def cache_key params = {}, the_profile = nil, language = 'en' - rand - end - - def can_display_hits? - false - end - - def can_display_media_panel? - true - end - -end diff --git a/app/models/environment.rb b/app/models/environment.rb index 4caf289..6b7365b 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -128,7 +128,6 @@ class Environment < ApplicationRecord 'disable_asset_enterprises' => _('Disable search for enterprises'), 'disable_asset_people' => _('Disable search for people'), 'disable_asset_communities' => _('Disable search for communities'), - 'disable_asset_products' => _('Disable search for products'), 'disable_asset_events' => _('Disable search for events'), 'disable_categories' => _('Disable categories'), 'disable_header_and_footer' => _('Disable header/footer editing by users'), @@ -139,7 +138,6 @@ class Environment < ApplicationRecord 'disable_contact_community' => _('Disable contact for groups/communities'), 'forbid_destroy_profile' => _('Forbid users of removing profiles'), - 'products_for_enterprises' => _('Enable products for enterprises'), 'enterprise_registration' => _('Enterprise registration'), 'enterprise_activation' => _('Enable activation of enterprises'), 'enterprises_are_disabled_when_created' => _('Enterprises are disabled when created'), @@ -226,7 +224,6 @@ class Environment < ApplicationRecord has_many :organizations has_many :enterprises - has_many :products, :through => :enterprises has_many :people has_many :communities has_many :licenses @@ -236,23 +233,16 @@ class Environment < ApplicationRecord order('display_color').where('display_color is not null and parent_id is null') }, class_name: 'Category' - has_many :product_categories, -> { where type: 'ProductCategory'} has_many :regions has_many :states has_many :cities has_many :roles, :dependent => :destroy - has_many :qualifiers - has_many :certifiers - has_many :mailings, :class_name => 'EnvironmentMailing', :foreign_key => :source_id, :as => 'source' acts_as_accessible - has_many :units, -> { order 'position' } - has_many :production_costs, :as => :owner - def superior_intances [self, nil] end @@ -441,9 +431,7 @@ class Environment < ApplicationRecord end DEFAULT_FEATURES = %w( - disable_asset_products disable_gender_icon - products_for_enterprises disable_select_city_for_contact enterprise_registration media_panel @@ -968,10 +956,6 @@ class Environment < ApplicationRecord end end - def highlighted_products_with_image(options = {}) - self.products.where(highlighted: true).joins(:image).order('created_at ASC') - end - settings_items :home_cache_in_minutes, :type => :integer, :default => 5 settings_items :general_cache_in_minutes, :type => :integer, :default => 15 settings_items :profile_cache_in_minutes, :type => :integer, :default => 15 diff --git a/app/models/featured_products_block.rb b/app/models/featured_products_block.rb deleted file mode 100644 index b6fd1d1..0000000 --- a/app/models/featured_products_block.rb +++ /dev/null @@ -1,35 +0,0 @@ -class FeaturedProductsBlock < Block - - attr_accessible :product_ids, :groups_of, :speed, :reflect - - settings_items :product_ids, :type => Array, :default => [] - settings_items :groups_of, :type => :integer, :default => 3 - settings_items :speed, :type => :integer, :default => 1000 - settings_items :reflect, :type => :boolean, :default => true - - before_save do |block| - if block.owner.kind_of?(Environment) && block.product_ids.blank? - total = block.owner.products.count - offset = rand([(total - block.groups_of * 3) + 1, 1].max) - block.product_ids = block.owner.highlighted_products_with_image.offset(offset).limit(block.groups_of * 3).map(&:id) - end - block.groups_of = block.groups_of.to_i - end - - def self.description - _('Featured Products') - end - - def self.pretty_name - _('Featured Products') - end - - def products - Product.find(self.product_ids) || [] - end - - def products_for_selection - self.owner.highlighted_products_with_image - end - -end diff --git a/app/models/input.rb b/app/models/input.rb deleted file mode 100644 index e9f2cd6..0000000 --- a/app/models/input.rb +++ /dev/null @@ -1,71 +0,0 @@ -class Input < ApplicationRecord - - attr_accessible :product, :product_id, :product_category, :product_category_id, - :amount_used, :unit_id, :price_per_unit, :relevant_to_price, :is_from_solidarity_economy - - belongs_to :product - belongs_to :product_category - - validates_presence_of :product - validates_presence_of :product_category - - acts_as_list scope: -> input { where product_id: input.product_id } - - belongs_to :unit - - scope :relevant_to_price, -> { where relevant_to_price: true } - - include FloatHelper - - def price_per_unit=(value) - if value.is_a?(String) - super(decimal_to_float(value)) - else - super(value) - end - end - - def amount_used=(value) - if value.is_a?(String) - super(decimal_to_float(value)) - else - super(value) - end - end - - def name - product_category.name - end - - def formatted_value(value) - ("%.2f" % self[value]).to_s.gsub('.', product.enterprise.environment.currency_separator) if self[value] - end - - def formatted_amount - amount = self.amount_used - return '' if amount.blank? || amount.zero? - ("%.2f" % amount).to_s.gsub('.00', '').gsub('.', product.enterprise.environment.currency_separator) - end - - def has_price_details? - %w[price_per_unit amount_used].each do |field| - return true unless self.send(field).blank? - end - false - end - - def has_all_price_details? - %w[price_per_unit unit amount_used].each do |field| - return false if self.send(field).blank? - end - true - end - - def cost - return 0 if self.amount_used.blank? || self.price_per_unit.blank? - self.amount_used * self.price_per_unit - end - - alias_method :price, :cost - -end diff --git a/app/models/price_detail.rb b/app/models/price_detail.rb deleted file mode 100644 index 02d120b..0000000 --- a/app/models/price_detail.rb +++ /dev/null @@ -1,33 +0,0 @@ -class PriceDetail < ApplicationRecord - - attr_accessible :price, :production_cost_id - - belongs_to :product - validates_presence_of :product_id - - belongs_to :production_cost - # Do not validates_presence_of production_cost. We may have undefined other costs. - validates_uniqueness_of :production_cost_id, :scope => :product_id - - def name - production_cost.nil? ? _('Other costs') : production_cost.name - end - - def price - self[:price] || 0 - end - - include FloatHelper - def price=(value) - if value.is_a?(String) - super(decimal_to_float(value)) - else - super(value) - end - end - - def formatted_value(value) - ("%.2f" % self[value]).to_s.gsub('.', product.enterprise.environment.currency_separator) if self[value] - end - -end diff --git a/app/models/product.rb b/app/models/product.rb deleted file mode 100644 index bac1cf5..0000000 --- a/app/models/product.rb +++ /dev/null @@ -1,291 +0,0 @@ -class Product < ApplicationRecord - - SEARCHABLE_FIELDS = { - :name => {:label => _('Name'), :weight => 10}, - :description => {:label => _('Description'), :weight => 1}, - } - - SEARCH_FILTERS = { - :order => %w[more_recent], - :display => %w[full map] - } - - attr_accessible :name, :product_category, :profile, :profile_id, :enterprise, - :highlighted, :price, :image_builder, :description, :available, :qualifiers, :unit_id, :discount, :inputs, :qualifiers_list - - def self.default_search_display - 'full' - end - - belongs_to :profile - # backwards compatibility - belongs_to :enterprise, :foreign_key => :profile_id, :class_name => 'Profile' - alias_method :enterprise=, :profile= - alias_method :enterprise, :profile - - has_one :region, :through => :profile - validates_presence_of :profile - - belongs_to :product_category - - has_many :inputs, -> { order 'position' }, dependent: :destroy - has_many :price_details, :dependent => :destroy - has_many :production_costs, :through => :price_details - - has_many :product_qualifiers, :dependent => :destroy - has_many :qualifiers, :through => :product_qualifiers - has_many :certifiers, :through => :product_qualifiers - - acts_as_having_settings :field => :data - - track_actions :create_product, :after_create, :keep_params => [:name, :url ], :if => Proc.new { |a| a.is_trackable? }, :custom_user => :action_tracker_user - track_actions :update_product, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? }, :custom_user => :action_tracker_user - track_actions :remove_product, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.is_trackable? }, :custom_user => :action_tracker_user - - validates_uniqueness_of :name, :scope => :profile_id, :allow_nil => true, :if => :validate_uniqueness_of_column_name? - - validates_presence_of :product_category_id - validates_associated :product_category - - validates_numericality_of :price, :allow_nil => true - validates_numericality_of :discount, :allow_nil => true - - scope :more_recent, -> { order 'created_at DESC' } - - scope :from_category, -> category { - joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category - } - - scope :visible_for_person, lambda { |person| - joins('INNER JOIN "profiles" enterprises ON enterprises."id" = "products"."profile_id"') - .joins('LEFT JOIN "role_assignments" ON ("role_assignments"."resource_id" = enterprises."id" - AND "role_assignments"."resource_type" = \'Profile\') OR ( - "role_assignments"."resource_id" = enterprises."environment_id" AND - "role_assignments"."resource_type" = \'Environment\' )') - .joins('LEFT JOIN "roles" ON "role_assignments"."role_id" = "roles"."id"') - .where( - ['( (roles.key = ? OR roles.key = ?) AND role_assignments.accessor_type = \'Profile\' AND role_assignments.accessor_id = ? ) - OR - ( ( ( role_assignments.accessor_type = \'Profile\' AND - role_assignments.accessor_id = ? ) OR - ( enterprises.public_profile = ? AND enterprises.enabled = ? ) ) AND - ( enterprises.visible = ? ) )', - 'profile_admin', 'environment_administrator', person.id, person.id, - true, true, true] - ).uniq - } - - scope :recent, -> limit=nil { order('id DESC').limit(limit) } - - after_update :save_image - - def lat - self.profile.lat - end - def lng - self.profile.lng - end - - xss_terminate :only => [ :name ], :on => 'validation' - xss_terminate :only => [ :description ], :with => 'white_list', :on => 'validation' - - belongs_to :unit - - include FloatHelper - - include WhiteListFilter - filter_iframes :description - - def iframe_whitelist - self.profile && self.profile.environment && self.profile.environment.trusted_sites_for_iframe - end - - def name - self[:name].blank? ? category_name : self[:name] - end - - def name=(value) - if (value == category_name) - self[:name] = nil - else - self[:name] = value - end - end - - def name_is_blank? - self[:name].blank? - end - - def default_image(size='thumb') - image ? image.public_filename(size) : '/images/icons-app/product-default-pic-%s.png' % size - end - - acts_as_having_image - - def save_image - image.save if image - end - - def category_name - product_category ? product_category.name : _('Uncategorized product') - end - - def url - self.profile.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id) - end - - def public? - self.profile.public? - end - - def formatted_value(method) - value = self[method] || self.send(method) - ("%.2f" % value).to_s.gsub('.', self.profile.environment.currency_separator) if value - end - - def price_with_discount - discount ? (price - discount) : price - end - - def price=(value) - if value.is_a?(String) - super(decimal_to_float(value)) - else - super(value) - end - end - - def discount=(value) - if value.is_a?(String) - super(decimal_to_float(value)) - else - super(value) - end - end - - def inputs_prices? - return false if self.inputs.count <= 0 - self.inputs.each do |input| - return false if input.has_price_details? == false - end - true - end - - def any_inputs_details? - return false if self.inputs.count <= 0 - self.inputs.each do |input| - return true if input.has_all_price_details? == true - end - false - end - - def has_basic_info? - %w[unit price discount].each do |field| - return true if !self.send(field).blank? - end - false - end - - def qualifiers_list=(qualifiers) - self.product_qualifiers.destroy_all - qualifiers.each do |qualifier_id, certifier_id| - if qualifier_id != 'nil' - product_qualifier = ProductQualifier.new - product_qualifier.product = self - product_qualifier.qualifier_id = qualifier_id - product_qualifier.certifier_id = certifier_id - product_qualifier.save! - end - end - end - - def order_inputs!(order = []) - order.each_with_index do |input_id, array_index| - input = self.inputs.find(input_id) - input.position = array_index + 1 - input.save! - end - end - - def name_with_unit - unit.blank? ? name : "#{name} - #{unit.name.downcase}" - end - - def display_supplier_on_search? - true - end - - def inputs_cost - return 0 if inputs.empty? - inputs.relevant_to_price.map(&:cost).inject { |sum,price| sum + price } - end - - def total_production_cost - return inputs_cost if price_details.empty? - inputs_cost + price_details.map(&:price).inject(0){ |sum,price| sum + price } - end - - def price_described? - return false if price.blank? or price == 0 - (price - total_production_cost.to_f).zero? - end - - def update_price_details(new_price_details) - price_details.destroy_all - new_price_details.each do |detail| - price_details.create(detail) - end - reload # to remove temporary duplicated price_details - price_details - end - - def price_description_percentage - return 0 if price.blank? || price.zero? - total_production_cost * 100 / price - end - - def available_production_costs - self.profile.environment.production_costs + self.profile.production_costs - end - - include Rails.application.routes.url_helpers - def price_composition_bar_display_url - url_for({:host => self.profile.default_hostname, :controller => 'manage_products', :action => 'display_price_composition_bar', :profile => self.profile.identifier, :id => self.id }.merge(Noosfero.url_options)) - end - - def inputs_cost_update_url - url_for({:host => self.profile.default_hostname, :controller => 'manage_products', :action => 'display_inputs_cost', :profile => self.profile.identifier, :id => self.id }.merge(Noosfero.url_options)) - end - - def percentage_from_solidarity_economy - se_i = t_i = 0 - self.inputs.each{ |i| t_i += 1; se_i += 1 if i.is_from_solidarity_economy } - t_i = 1 if t_i == 0 # avoid division by 0 - p = case (se_i.to_f/t_i)*100 - when 0 then [0, ''] - when 0..24.999 then [0, _("0%")]; - when 25..49.999 then [25, _("25%")]; - when 50..74.999 then [50, _("50%")]; - when 75..99.999 then [75, _("75%")]; - when 100 then [100, _("100%")]; - end - end - - delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :profile, allow_nil: true - - protected - - def validate_uniqueness_of_column_name? - true - end - - def is_trackable? - # shopping_cart create products without profile - self.profile.present? - end - - def action_tracker_user - self.profile - end - -end diff --git a/app/models/product_categories_block.rb b/app/models/product_categories_block.rb deleted file mode 100644 index 4b81eb6..0000000 --- a/app/models/product_categories_block.rb +++ /dev/null @@ -1,30 +0,0 @@ -class ProductCategoriesBlock < Block - - def self.description - _('Product category menu') - end - - # the title of the block. Probably will be overriden in subclasses. - def default_title - _('Catalog') - end - - def help - _('Helps to filter the products catalog.') - end - - DISPLAY_OPTIONS = DISPLAY_OPTIONS.merge('catalog_only' => _('Only on the catalog')) - - def display - settings[:display].nil? ? 'catalog_only' : super - end - - def display_catalog_only(context) - context[:params][:controller] == 'catalog' - end - - def visible?(*args) - box.environment.enabled?('products_for_enterprises') ? super(*args) : false - end - -end diff --git a/app/models/product_category.rb b/app/models/product_category.rb deleted file mode 100644 index e1bccd5..0000000 --- a/app/models/product_category.rb +++ /dev/null @@ -1,29 +0,0 @@ -class ProductCategory < Category - # FIXME: do not allow category with products or inputs to be destroyed - has_many :products - has_many :inputs - - attr_accessible :name, :parent, :environment - - scope :unique, -> { select 'DISTINCT ON (path) categories.*' } - scope :by_enterprise, -> enterprise { - distinct.joins(:products). - where('products.profile_id = ?', enterprise.id) - } - scope :by_environment, -> environment { - where 'environment_id = ?', environment.id - } - - scope :unique_by_level, lambda { |level| { - :select => "DISTINCT ON (filtered_category) split_part(path, '/', #{level.to_i}) AS filtered_category, categories.*" - }} - - def all_products - Product.where(product_category_id: (all_children << self).map(&:id)) - end - - def self.menu_categories(top_category, env) - top_category ? top_category.children : top_level_for(env).select{|c|c.kind_of?(ProductCategory)} - end - -end diff --git a/app/models/product_qualifier.rb b/app/models/product_qualifier.rb deleted file mode 100644 index c6b222a..0000000 --- a/app/models/product_qualifier.rb +++ /dev/null @@ -1,8 +0,0 @@ -class ProductQualifier < ApplicationRecord - - attr_accessible :qualifier, :product, :certifier - - belongs_to :qualifier - belongs_to :product - belongs_to :certifier -end diff --git a/app/models/production_cost.rb b/app/models/production_cost.rb deleted file mode 100644 index e527e0b..0000000 --- a/app/models/production_cost.rb +++ /dev/null @@ -1,11 +0,0 @@ -class ProductionCost < ApplicationRecord - - attr_accessible :name, :owner - - belongs_to :owner, :polymorphic => true - validates_presence_of :owner - validates_presence_of :name - validates_length_of :name, :maximum => 30, :allow_blank => true - validates_uniqueness_of :name, :scope => [:owner_id, :owner_type] - -end diff --git a/app/models/products_block.rb b/app/models/products_block.rb deleted file mode 100644 index bb80037..0000000 --- a/app/models/products_block.rb +++ /dev/null @@ -1,38 +0,0 @@ -class ProductsBlock < Block - - attr_accessible :product_ids - - include ActionView::Helpers::TagHelper - include ActionView::Helpers::UrlHelper - include ActionView::Helpers - include Rails.application.routes.url_helpers - - def self.description - _('Products') - end - - def default_title - _('Products') - end - - def help - _('This block presents a list of your products.') - end - - settings_items :product_ids, type: Array - def product_ids=(array) - self.settings[:product_ids] = array - if self.settings[:product_ids] - self.settings[:product_ids] = self.settings[:product_ids].map(&:to_i) - end - end - - def products(reload = false) - if product_ids.blank? - owner.products.order('RANDOM()').limit([4,owner.products.count].min) - else - owner.products.where(:id => product_ids) - end.compact - end - -end diff --git a/app/models/profile.rb b/app/models/profile.rb index 2045f88..e4eb8b3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -812,7 +812,7 @@ private :generate_url, :url_options end def accept_category?(cat) - forbidden = [ ProductCategory, Region ] + forbidden = [ Region ] !forbidden.include?(cat.class) end diff --git a/app/models/qualifier.rb b/app/models/qualifier.rb deleted file mode 100644 index 3ef1e05..0000000 --- a/app/models/qualifier.rb +++ /dev/null @@ -1,30 +0,0 @@ -class Qualifier < ApplicationRecord - - attr_accessible :name, :environment - - SEARCHABLE_FIELDS = { - :name => {:label => _('Name'), :weight => 1}, - } - - belongs_to :environment - - has_many :qualifier_certifiers, :dependent => :destroy - has_many :certifiers, :through => :qualifier_certifiers - - def used_certs - Certifier.joins('INNER JOIN product_qualifiers' + - ' ON certifiers.id = product_qualifiers.certifier_id') - .where(product_qualifiers: {qualifier_id: self.id}) - end - - has_many :product_qualifiers, :dependent => :destroy - has_many :products, :through => :product_qualifiers, :source => :product - - validates_presence_of :environment_id - validates_presence_of :name - - def <=>(b) - self.name.downcase.transliterate <=> b.name.downcase.transliterate - end - -end diff --git a/app/models/qualifier_certifier.rb b/app/models/qualifier_certifier.rb deleted file mode 100644 index 7aaa984..0000000 --- a/app/models/qualifier_certifier.rb +++ /dev/null @@ -1,6 +0,0 @@ -class QualifierCertifier < ApplicationRecord - belongs_to :qualifier - belongs_to :certifier - - validates_presence_of :qualifier -end diff --git a/app/models/sellers_search_block.rb b/app/models/sellers_search_block.rb deleted file mode 100644 index 085f92b..0000000 --- a/app/models/sellers_search_block.rb +++ /dev/null @@ -1,25 +0,0 @@ -class SellersSearchBlock < Block - - attr_accessible :title - - def self.description - _('Search for enterprises and products') - end - - def self.short_description - _('Products/Enterprises search') - end - - def self.pretty_name - _('Sellers Search') - end - - def default_title - _('Search for sellers') - end - - def help - _('This block presents a search engine for products.') - end - -end diff --git a/app/models/unit.rb b/app/models/unit.rb deleted file mode 100644 index 0502dcd..0000000 --- a/app/models/unit.rb +++ /dev/null @@ -1,23 +0,0 @@ -class Unit < ApplicationRecord - - acts_as_list scope: -> unit { where environment_id: unit.environment_id } - - attr_accessible :name, :singular, :plural, :environment - - validates_presence_of :singular - validates_presence_of :plural - - belongs_to :environment - - validates_presence_of :environment_id - validates_presence_of :singular - validates_presence_of :plural - - def name - self.singular - end - def name=(value) - self.singular = value - end - -end diff --git a/app/views/blocks/footers/products.html.erb b/app/views/blocks/footers/products.html.erb deleted file mode 100644 index 5fa18ff..0000000 --- a/app/views/blocks/footers/products.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= link_to(_('View all products'), block.owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) %> diff --git a/app/views/blocks/product_categories.html.erb b/app/views/blocks/product_categories.html.erb deleted file mode 100644 index 3288ec0..0000000 --- a/app/views/blocks/product_categories.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% - if @categories.nil? or @categories.length == 0 - categories = ProductCategory.on_level(nil).order(:name) - else - categories = @categories - end -%> - -<%= link_to _('Catalog start'), block.owner.catalog_url, :class=>'catalog-home-link' %> -

-<% if @categories and @categories.length == 0 %> -
- <%= _('There are no sub-categories for %s') % @category.name %> -
-<% end %> diff --git a/app/views/blocks/products.html.erb b/app/views/blocks/products.html.erb deleted file mode 100644 index 0cf0d9a..0000000 --- a/app/views/blocks/products.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<%= block_title(block.title, block.subtitle) %> - - diff --git a/app/views/blocks/profile_info.html.erb b/app/views/blocks/profile_info.html.erb index 39025a6..895f3d0 100644 --- a/app/views/blocks/profile_info.html.erb +++ b/app/views/blocks/profile_info.html.erb @@ -16,9 +16,6 @@