forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
products_controller.rb
46 lines (38 loc) · 1.27 KB
/
products_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
@products = @searcher.retrieve_products
respond_with(@products)
end
def show
return unless @product
@variants = @product.variants_including_master.active.includes([:option_values, :images])
@product_properties = @product.product_properties.includes(:property)
referer = request.env['HTTP_REFERER']
if referer
referer_path = URI.parse(request.env['HTTP_REFERER']).path
if referer_path && referer_path.match(/\/t\/(.*)/)
@taxon = Taxon.find_by_permalink($1)
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.find_by_permalink!(params[:id])
end
end
end
end