1 class StoreController
< ApplicationController
2 before_filter
:find_cart, :except => :empty_cart
5 @products = Product
.find_products_for_sale
10 product
= Product
.find(params
[:id])
12 @current_item = @cart.add_product(product
)
13 respond_to
do |format
|
14 format
.js
if request
.xhr
?
15 format
.html
{redirect_to_index
}
17 rescue ActiveRecord
::RecordNotFound
18 logger
.error("Attempt to access invalid product #{params[:id]}" )
19 redirect_to_index('Invalid product')
24 redirect_to_index
unless request
.xhr
?
30 redirect_to_index("Your cart is empty" )
33 @during_checkout = true
34 respond_to
do |format
|
35 format
.js
if request
.xhr
?
43 @order = Order
.new(params
[:order])
44 # @order.add_line_items_from_cart(@cart)
45 @cart.items
.each
do |item
|
47 li
.product
= item
.product
48 li
.quantity
= item
.quantity
49 li
.total_price
= item
.price
50 @order.line_items
<< li
54 redirect_to_index("Thank you for your order")
56 render
:action => 'checkout'
58 @during_checkout = false
64 # No authorization needed for the store
71 @cart = (session
[:cart] ||= Cart
.new
)
74 def redirect_to_index(msg
= nil)
75 flash
[:notice] = msg
if msg
76 redirect_to
:action => 'index'