Class: Refinery::Stores::StoresController

Inherits:
Refinery::StoresApplicationController show all
Defined in:
app/controllers/refinery/stores/stores_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_to_cartObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/refinery/stores/stores_controller.rb', line 30

def add_to_cart
  begin                     
    product = ::Refinery::Products::Product.find(params[:id])  
  rescue ActiveRecord::RecordNotFound
    logger.error("Attempt to access invalid product #{params[:id]}")
    redirect_to_index("Invalid product")
  else
    @current_item = @cart.add_product(product)
    redirect_to_index unless request.xhr?
  end
end

#checkoutObject



48
49
50
51
52
53
54
55
56
# File 'app/controllers/refinery/stores/stores_controller.rb', line 48

def checkout
  if @cart.items.empty?
    redirect_to_index("Your cart is empty")
  else
    @order = ::Refinery::Orders::Order.checkout!( @cart, current_refinery_user )
    session[:cart] = nil
    redirect_to   refinery.edit_orders_order_path( @order )
  end
end

#empty_cartObject



42
43
44
45
# File 'app/controllers/refinery/stores/stores_controller.rb', line 42

def empty_cart
  session[:cart] = nil
  redirect_to_index
end

#indexObject



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/refinery/stores/stores_controller.rb', line 12

def index
  # you can use meta fields from your model instead (e.g. browser_title)
  # by swapping @page for @store in the line below:
  if @store.nil?  # if there is no active store
    find_all_stores   # then prob show an empty page
    present(@page)
  else  # else show the active store directly
    redirect_to refinery.stores_store_path( @store )
  end
end

#showObject



23
24
25
26
27
28
# File 'app/controllers/refinery/stores/stores_controller.rb', line 23

def show

  # you can use meta fields from your model instead (e.g. browser_title)
  # by swapping @page for @store in the line below:
  present(@page)
end