1 class StoreController
< ApplicationController
3 @products = Product
.find_products_for_sale
8 product
= Product
.find(params
[:id])
10 @current_item = @cart.add_product(product
)
11 respond_to
do |format
|
12 format
.js
if request
.xhr
?
13 format
.html
{redirect_to_index
}
15 rescue ActiveRecord
::RecordNotFound
16 logger
.error("Attempt to access invalid product #{params[:id]}" )
17 redirect_to_index('Invalid product')
22 redirect_to_index
unless request
.xhr
?
28 redirect_to_index("Your cart is empty" )
31 @during_checkout = true
32 respond_to
do |format
|
33 format
.js
if request
.xhr
?
41 @order = Order
.new(params
[:order])
42 # @order.add_line_items_from_cart(@cart)
43 @cart.items
.each
do |item
|
45 li
.product
= item
.product
46 li
.quantity
= item
.quantity
47 li
.total_price
= item
.price
48 @order.line_items
<< li
52 redirect_to_index("Thank you for your order")
54 render
:action => 'checkout'
56 @during_checkout = false
63 session
[:cart] ||= Cart
.new
66 def redirect_to_index(msg
= nil)
67 flash
[:notice] = msg
if msg
68 redirect_to
:action => 'index'