Sha256: 291b14b8830250f2ff72e645e17eca1725a7822695a452350cab6524000a4440

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

module Spree
  class ProductsController < Spree::StoreController
    before_filter :load_product, :only => :show
    rescue_from ActiveRecord::RecordNotFound, :with => :render_404
    helper 'spree/taxons'

    respond_to :html

    def index
      @searcher = Config.searcher_class.new(params)
      @searcher.current_user = try_spree_current_user
      @searcher.current_currency = current_currency
      @products = @searcher.retrieve_products
      respond_with(@products)
    end

    def show
      return unless @product

      @variants = @product.variants_including_master.active(current_currency).includes([:option_values, :images])
      @product_properties = @product.product_properties.includes(:property)

      referer = request.env['HTTP_REFERER']
      if referer
        begin
          referer_path = URI.parse(request.env['HTTP_REFERER']).path
          # Fix for #2249
        rescue URI::InvalidURIError
          # Do nothing
        else
          if referer_path && referer_path.match(/\/t\/(.*)/)
            @taxon = Taxon.find_by_permalink($1)
          end
        end
      end

      respond_with(@product)
    end

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

      def load_product
        if try_spree_current_user.try(:has_spree_role?, "admin")
          @product = Product.find_by_permalink!(params[:id])
        else
          @product = Product.active(current_currency).find_by_permalink!(params[:id])
        end
      end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
spree_core-1.3.5 app/controllers/spree/products_controller.rb
spree_core-1.3.4 app/controllers/spree/products_controller.rb
spree_core-1.3.3 app/controllers/spree/products_controller.rb
spree_core-1.3.2 app/controllers/spree/products_controller.rb
spree_core-1.3.1 app/controllers/spree/products_controller.rb
spree_core-1.3.0 app/controllers/spree/products_controller.rb
spree_core-1.3.0.rc2 app/controllers/spree/products_controller.rb
dup_spree_core-1.3.0.rc1 app/controllers/spree/products_controller.rb
spree_core-1.3.0.rc1 app/controllers/spree/products_controller.rb