Sha256: 93eae624ff90c02bbed2b639a006cdaab06694cba98f22fb9f29f5d1b0099964
Contents?: true
Size: 1.28 KB
Versions: 4
Compression:
Stored size: 1.28 KB
Contents
class CartController < ApplicationController layout :layout unloadable def index @cart = find_cart() end def update cart = find_cart() if params.key?('quantity_total_update') && params.key?('cart_item') # We are updating the total quantity of multiple items in teh cart. This is likely from teh cart page where # the user has updated the quantity text fields and clicked 'Update Cart' params['cart_item'].each do |item_id, data| cart_item = CartItem.find_by_id(item_id) if data.key?('quantity') cart.set_item_quantity(cart_item.product, data['quantity'].to_i) end end flash[:notice] = "Your cart has been updated." else # Adding a given number (quanity) of a particular product. Probably an add to cart from the product page product = Product.find_by_id(params[:product_id]) quantity = (params[:quantity] || 1).to_i cart.add(product, quantity) flash[:notice] = "#{quantity} #{quantity==1 ? 'item' : 'items'} #{quantity == 1 ? 'has' : 'have'} been added to your <a href='/cart'>cart</a>.".html_safe end redirect_to :back end def destroy session[:cart] = nil flash[:notice] = "Your cart has been emptied." redirect_to :back end def confirmation end end
Version data entries
4 entries across 4 versions & 1 rubygems