Class: CompareProductsController
- Inherits:
-
Spree::BaseController
- Object
- Spree::BaseController
- CompareProductsController
- Defined in:
- app/controllers/compare_products_controller.rb
Constant Summary collapse
- COMPARE_LIMIT =
4
Instance Method Summary collapse
Instance Method Details
#add ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/compare_products_controller.rb', line 15 def add product = Product.find_by_permalink(params[:id]) if product && (product.taxons.map(&:id).include?(@taxon.try(:id)) || @comparable_products.size < 1) if session[:comparable_product_ids].include?(product.id) flash[:notice] = I18n.t(:already_in_list, :product => product.name, :scope => :compare_products) else if @comparable_products.size < COMPARE_LIMIT @added_product = product session[:comparable_product_ids] << product.id flash[:notice] = I18n.t(:added_to_comparsion, :product => product.name, :scope => :compare_products) else flash[:notice] = I18n.t(:limit_is_reached, :scope => :compare_products, :count => COMPARE_LIMIT) end end else session[:comparable_product_ids].delete(product.id) flash[:error] = I18n.t(:invalid_taxon, :scope => :compare_products) end respond_to do |format| format.html { redirect_back_or_default(products_path) } format.js { render :layout => false } end end |
#destroy ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'app/controllers/compare_products_controller.rb', line 53 def destroy session[:comparable_product_ids] = [] flash[:notice] = I18n.t(:comparsion_cleared, :scope => :compare_products) respond_to do |format| format.html { redirect_back_or_default(products_path) } format.js { render :layout => false } end end |
#remove ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/compare_products_controller.rb', line 39 def remove session[:comparable_product_ids] ||= [] product = Product.find_by_permalink(params[:id]) if product @deleted_product = product if session[:comparable_product_ids].include?(product.id) session[:comparable_product_ids].delete(product.id) flash[:notice] = I18n.t(:removed_from_comparsion, :product => product.name, :scope => :compare_products) end respond_to do |format| format.html { redirect_back_or_default(products_path) } format.js { render :layout => false } end end |
#show ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/controllers/compare_products_controller.rb', line 7 def show if @comparable_products.count > 1 @properties = @comparable_products.includes(:product_properties => :property).map(&:properties).flatten.uniq # We return the list of properties here so we can use them latter. else flash[:error] = I18n.t(:insufficient_data, :scope => :compare_products) end end |