Sha256: 2ce86a2f480240f83d1c223c60714627a4a4eab72e63af17d317d37b23775ca7

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

module Comable
  class ProductsController < Comable::ApplicationController
    before_filter :load_category_and_products, only: :index

    def index
      @products = @products.page(params[:page]).per(Comable::Config.products_per_page)
    end

    def show
      @product = preview? ? Comable::Product.find(params[:id]) : Comable::Product.published.find(params[:id])
    end

    private

    def load_category_and_products
      @category = Comable::Category.where(id: params[:category_id]).first
      if @category
        subtree_of_category = Comable::Category.subtree_of(@category)
        @products = Comable::Product.published.eager_load(:categories).merge(subtree_of_category)
      else
        @products = Comable::Product.published.search(params[:q])
      end
    end

    def preview?
      session[Comable::Product::PREVIEW_SESSION_KEY] ||= {}
      session[Comable::Product::PREVIEW_SESSION_KEY][params[:id]]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comable-frontend-0.7.0.beta1 app/controllers/comable/products_controller.rb