X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=app%2Fcontrollers%2Fpurchase_controller.rb;fp=app%2Fcontrollers%2Fpurchase_controller.rb;h=704e38b78b0e03737cbcb732b15bae02096df0ff;hb=74561aac0964ca7bd9283ad0a9b017e02431f845;hp=4445c07b838352860e3cb499bebf4fe890954c22;hpb=56db4e1da35c068e247eadbd32edd0a09eb61127;p=cs356-p2-videostore.git diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index 4445c07..704e38b 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -12,6 +12,7 @@ class PurchaseController < ApplicationController # enter a customer id here render :action => 'begin' session[:total] = 0.00 + session[:items] = [] end def customer_ok @@ -27,6 +28,7 @@ class PurchaseController < ApplicationController def menu @customer = Customer.find_by_id(session[:customer_id]) @total_price = session[:total] + @items = session[:items] render :action => 'menu' end @@ -69,10 +71,13 @@ class PurchaseController < ApplicationController purchase.customer_id = session[:customer_id] purchase.date = Time.now.to_date purchase.price = @rentable.calculated_price - session[:total] += @rentable.calculated_price purchase.rentable = @rentable purchase.save! + # Add te session variables + session[:total] += @rentable.calculated_price + session[:items].push @rentable + flash[:notice] = "Successfully made purchase" redirect_to :action => :menu end @@ -108,11 +113,14 @@ class PurchaseController < ApplicationController purchase.customer_id = session[:customer_id] purchase.date = Time.now.to_date purchase.price = @merchandise.price - session[:total] += @merchandise.price purchase.merchandise = @merchandise purchase.quantity = 1 @merchandise.quantity -= 1 + # Add to session variables + session[:total] += @merchandise.price + session[:items].push @merchandise + # Save both the merchandise (we changed the quantity) and the purchase to the log @merchandise.save! purchase.save!