Class: Sprangular::ProductsController
Instance Method Summary
collapse
#invalid_resource!, #not_found, #unauthorized
Instance Method Details
#index ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/controllers/sprangular/products_controller.rb', line 2
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
|
#show ⇒ Object
21
22
23
24
25
26
|
# File 'app/controllers/sprangular/products_controller.rb', line 21
def show
@product = product_scope.where(slug: params[:id]).first!
render json: @product, root: false,
serializer: Sprangular::ProductSerializer
end
|