Sha256: 8ab6f6ac1850c967544723e266f98d9f2a98d2beb168aac8c9e92d8f61c5d365

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Gemgento
  class CategoriesController < ApplicationController

    before_filter :set_filters, only: :show
    after_filter :set_last_category, only: :show

    def index
      @current_category = Category.root
      @categories = Category.top_level
    end

    def show
      @current_category = Gemgento::Category.active.find_by!('id = ? OR url_key = ?', params[:id], params[:id])
      @products = current_category.products.active.catalog_visible
      @products = @products.filter(@filters) unless @filters.empty?
      @products = @products.page(params[:page]).per(params[:per])
    end

    private

    # Get an array of all the active filters.
    #
    # @return [Array(Hash(:attribute, :value, :operand))]
    def set_filters
      @filters ||= begin
        filters = []
        filters << { attribute: Gemgento::ProductAttribute.find_by!(code: 'color'), value: params[:color] } unless params[:color].blank?
        filters
      end
    end

    def set_last_category
      session[:category] = @current_category.id
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemgento-2.8.0 app/controllers/gemgento/categories_controller.rb