Permalink
Browse files

added empty cart, and also the buy now is working

  • Loading branch information...
1 parent 140b0a4 commit 287ee2556498d6f8c5f83df11bc324507a4b826c @florida committed Nov 16, 2012
Showing with 15 additions and 1 deletion.
  1. +7 −0 app/controllers/store_controller.rb
  2. +8 −1 app/models/cart.rb
@@ -17,10 +17,17 @@ def show_cart
render 'shoppingcart'
end
+ def empty_cart
+ @cart = get_cart
+ @cart.empty_cart_contents!
+ flash[:notice] = ' Your cart is now empty'
+ redirect_to store_path
+ end
private
def get_cart
session[:cart] ||= Cart.new
end
+
end
View
@@ -19,11 +19,18 @@ def add_line_item(product)
item = @items.find {|i| i.product_id == product.id}
if item
- item.quantiy += 1
+ item.quantity += 1
else
item = Lineitem.add_product(product)
@items << item
end
@total_price += product.price
end
+
+
+ def empty_cart_contents!
+ @items = []
+ @total_price = 0.0
+ @taxes = 0.0
+ end
end

0 comments on commit 287ee25

Please sign in to comment.