Class: ProductsController

Inherits:
Spree::BaseController show all
Defined in:
app/controllers/products_controller.rb

Constant Summary collapse

HTTP_REFERER_REGEXP =
/^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+)$/

Instance Method Summary collapse

Methods included from SpreeBase

included

Methods inherited from ActionController::Base

#respond_with

Instance Method Details

#indexObject



8
9
10
11
12
13
# File 'app/controllers/products_controller.rb', line 8

def index
  @searcher = Spree::Config.searcher_class.new(params)
  @products = @searcher.retrieve_products

  respond_with(@products)
end

#showObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/products_controller.rb', line 15

def show
  @product = Product.find_by_permalink!(params[:id])
  return unless @product

  @variants = Variant.active.includes([:option_values, :images]).where(:product_id => @product.id)
  @product_properties = ProductProperty.includes(:property).where(:product_id => @product.id)
  @selected_variant = @variants.detect { |v| v.available? }

  referer = request.env['HTTP_REFERER']

  if referer && referer.match(HTTP_REFERER_REGEXP)
    @taxon = Taxon.find_by_permalink($1)
  end

  respond_with(@product)
end