Sha256: a0f7457a6ad8f9aa9ceb2ef938bdc00da147f6cf7581706f28c26bf188a7531c

Contents?: true

Size: 2 KB

Versions: 13

Compression:

Stored size: 2 KB

Contents

module Spree
  class ProductsController < Spree::StoreController
    before_action :load_product, only: :show
    before_action :load_taxon, only: :index

    rescue_from ActiveRecord::RecordNotFound, with: :render_404
    helper 'spree/taxons'

    respond_to :html

    def index
      @searcher = build_searcher(params.merge(include_images: true))
      @products = @searcher.retrieve_products
      @products = @products.includes(:possible_promotions) if @products.respond_to?(:includes)
      @taxonomies = Spree::Taxonomy.includes(root: :children)
    end

    def show
      @variants = @product.variants_including_master.
                           spree_base_scopes.
                           active(current_currency).
                           includes([:option_values, :images])
      @product_properties = @product.product_properties.includes(:property)
      @taxon = params[:taxon_id].present? ? Spree::Taxon.find(params[:taxon_id]) : @product.taxons.first
      redirect_if_legacy_path
    end

    private

      def accurate_title
        if @product
          @product.meta_title.blank? ? @product.name : @product.meta_title
        else
          super
        end
      end

      def load_product
        if try_spree_current_user.try(:has_spree_role?, "admin")
          @products = Product.with_deleted
        else
          @products = Product.active(current_currency)
        end
        @product = @products.includes(:variants_including_master, variant_images: :viewable).friendly.find(params[:id])
      end

      def load_taxon
        @taxon = Spree::Taxon.find(params[:taxon]) if params[:taxon].present?
      end

      def redirect_if_legacy_path
        # If an old id or a numeric id was used to find the record,
        # we should do a 301 redirect that uses the current friendly id.
        if params[:id] != @product.friendly_id
          params[:id] = @product.friendly_id
          params.permit!
          return redirect_to url_for(params), status: :moved_permanently
        end
      end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spree_frontend-3.2.9 app/controllers/spree/products_controller.rb
spree_frontend-3.2.8 app/controllers/spree/products_controller.rb
spree_frontend-3.2.7 app/controllers/spree/products_controller.rb
spree_frontend-3.2.6 app/controllers/spree/products_controller.rb
spree_frontend-3.2.5 app/controllers/spree/products_controller.rb
spree_frontend-3.2.4 app/controllers/spree/products_controller.rb
spree_frontend-3.2.3 app/controllers/spree/products_controller.rb
spree_frontend-3.2.2 app/controllers/spree/products_controller.rb
spree_frontend-3.2.1 app/controllers/spree/products_controller.rb
spree_frontend-3.2.0 app/controllers/spree/products_controller.rb
spree_frontend-3.2.0.rc3 app/controllers/spree/products_controller.rb
spree_frontend-3.2.0.rc2 app/controllers/spree/products_controller.rb
spree_frontend-3.2.0.rc1 app/controllers/spree/products_controller.rb