Sha256: d1172170660708adf4444f764ee1d7ab6acc5d9ca3471219b858888c20ad334b

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

class Sprangular::ProductsController < Sprangular::BaseController
  def index
    @products = product_scope
    @products = @products.where("spree_prices.amount IS NOT NULL").where("spree_prices.currency" => current_currency) unless Spree::Config.show_products_without_price
    @products = @products.ransack(params[:q]).result if params[:q]
    @products = @products.distinct.page(params[:page]).per(params[:per_page])
    @cache_key = [I18n.locale, @current_user_roles.include?('admin'), current_currency, params[:q], params[:per_page], params[:per_page]]

    render json: @products,
           each_serializer: Sprangular::ProductSerializer,
           root: :products,
           meta: {
             count: @products.count,
             total_count: @products.total_count,
             current_page: params[:page] ? params[:page].to_i : 1,
             per_page: params[:per_page] || Kaminari.config.default_per_page,
             pages: @products.num_pages
           }
  end

  def show
    @product = product_scope.where(slug: params[:id]).first!

    render json: @product, root: false,
           serializer: Sprangular::ProductSerializer
  end

  private

  def product_scope
    Spree::Product.active.includes(:option_types, :taxons, master: [:images, :option_values, :prices], product_properties: [:property], variants: [:images, :option_values, :prices])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sprangular-0.1.0 app/controllers/sprangular/products_controller.rb