Sha256: c6b590c1fe4c69bb70ec55936c3e833f9c0ebc191a4acaa28a0b9ae2fa0e98eb

Contents?: true

Size: 982 Bytes

Versions: 7

Compression:

Stored size: 982 Bytes

Contents

class ProductsController < Spree::BaseController
  HTTP_REFERER_REGEXP = /^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+)$/
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
  helper :taxons

  respond_to :html

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

    respond_with(@products)
  end

  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

  private

  def accurate_title
    @product ? @product.name : super
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-0.60.6 app/controllers/products_controller.rb
spree_core-0.60.5 app/controllers/products_controller.rb
spree_core-0.60.4 app/controllers/products_controller.rb
spree_core-0.60.3 app/controllers/products_controller.rb
spree_core-0.60.2 app/controllers/products_controller.rb
spree_core-0.60.1 app/controllers/products_controller.rb
spree_core-0.60.0 app/controllers/products_controller.rb