Sha256: ba2f7d450663fa64244782029a2aabef4f3d4ed4cc1f27feb9ac393ec03da6c1

Contents?: true

Size: 1011 Bytes

Versions: 2

Compression:

Stored size: 1011 Bytes

Contents

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

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

    def show
      products = Comable::Product.includes(:variants)
      @product = preview? ? products.find(params[:id]) : products.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

2 entries across 2 versions & 1 rubygems

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