Class: Spree::ProductsController

Inherits:
StoreController show all
Includes:
FrontendHelper, ProductsHelper
Defined in:
app/controllers/spree/products_controller.rb

Instance Method Summary collapse

Methods included from FrontendHelper

#asset_exists?, #available_option_types, #available_option_types_cache_key, #body_class, #carousel_image_source_set, #checkout_progress, #class_for, #filtering_params, #filtering_params_cache_key, #flash_messages, #icon, #image_source_set, #lazy_image, #link_to_cart, #permitted_product_params, #plp_and_carousel_image, #price_filter_values, #set_image_alt, #spree_breadcrumbs, #spree_social_link, #static_filters, #taxons_tree

Methods inherited from StoreController

#account_link, #api_tokens, #cart_link, #ensure_cart, #forbidden, #unauthorized

Instance Method Details

#indexObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/spree/products_controller.rb', line 11

def index
  @searcher = build_searcher(params.merge(include_images: true))
  @products = @searcher.retrieve_products

  last_modified = @products.maximum(:updated_at)&.utc if @products.respond_to?(:maximum)

  etag = [
    store_etag,
    last_modified&.to_i,
    available_option_types_cache_key,
    filtering_params_cache_key
  ]

  fresh_when etag: etag, last_modified: last_modified, public: true
end


41
42
43
44
45
46
47
48
49
# File 'app/controllers/spree/products_controller.rb', line 41

def related
  @related_products = related_products

  if @related_products.any?
    render template: 'spree/products/related', layout: false
  else
    head :no_content
  end
end

#showObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/spree/products_controller.rb', line 27

def show
  redirect_if_legacy_path

  @taxon = params[:taxon_id].present? ? Spree::Taxon.find(params[:taxon_id]) : @product.taxons.first

  if stale?(etag: product_etag, last_modified: @product.updated_at.utc, public: true)
    @product_summary = Spree::ProductSummaryPresenter.new(@product).call
    @product_properties = @product.product_properties.includes(:property)
    @product_price = @product.price_in(current_currency).amount
    load_variants
    @product_images = product_images(@product, @variants)
  end
end