Class: Opensteam::ShoppingCart::CartController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Opensteam::ShoppingCart::CartController
- Defined in:
- lib/opensteam/shopping_cart.rb
Overview
CartController
-
standard methods for ShoppingCart manipulation
-
automatically sets @cart to access shopping-cart
Direct Known Subclasses
Instance Method Summary collapse
-
#add_inventory_to_cart ⇒ Object
add an inventory object to the shopping cart.
- #decr_quantity ⇒ Object
-
#del_item ⇒ Object
delete item from cart.
-
#empty_cart ⇒ Object
empty cart.
- #incr_quantity ⇒ Object
-
#show_cart_item ⇒ Object
show item from cart.
-
#update_quantity ⇒ Object
update quantity for item in cart params = { “item_id” => “quantity }.
Instance Method Details
#add_inventory_to_cart ⇒ Object
add an inventory object to the shopping cart
-
finds the product + inventory object (based on selected properties)
-
checks if product is available
-
add inventory object to cart
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/opensteam/shopping_cart.rb', line 54 def add_inventory_to_cart if request.post? params[:product] = frmt params[:product] if params[:product][:properties] && params[:product][:properties].index("") flash[:error] = "Please select a #{params[:product][:properties].index("").humanize}" return end product = Opensteam::Find.find_product_with_inventory( params[:product] ) if product.is_available? unless @cart.add product.selected_inventories.last.id render :update do |page| page.alert "Sorry, there are only #{product.selected_inventories.last.storage} available!" end end else render :update do |page| page.alert "Sorry, this product is currently not available!" end end end end |
#decr_quantity ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/opensteam/shopping_cart.rb', line 95 def decr_quantity if request.post? ( ( ci = @cart.get( :cart_item_id => params[:id] ) ).quantity - 1 ) == 0 ? @cart.items.delete_at( params[:id].to_i ) : ci.decr ; end if session[:active_order] render :template => "checkout/update_cart_content.rjs" else render :action => "add_inventory_to_cart.rjs" end end |
#del_item ⇒ Object
delete item from cart
28 29 30 31 32 |
# File 'lib/opensteam/shopping_cart.rb', line 28 def del_item get_cart.del( :cart_item_id => params[:id]) @current_item = params[:id] redirect_to_index unless request.xhr? end |
#empty_cart ⇒ Object
empty cart
133 134 135 136 |
# File 'lib/opensteam/shopping_cart.rb', line 133 def empty_cart wipe_cart redirect_to_index end |
#incr_quantity ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/opensteam/shopping_cart.rb', line 78 def incr_quantity if request.post? ci = @cart.get( :cart_item_id => params[:id] ) unless ci.incr render :update do |page| page.alert "Sorry, there are only #{ci.quantity} available!" end return end end if session[:active_order] render :template => "checkout/update_cart_content.rjs" else render :action => "add_inventory_to_cart.rjs" end end |
#show_cart_item ⇒ Object
show item from cart
37 38 39 40 41 42 43 44 45 |
# File 'lib/opensteam/shopping_cart.rb', line 37 def show_cart_item i = Opensteam::InventoryBase::Inventory.find( @cart.items[ params[:id].to_i ].yamlid ) @product = i.product @inventory = [i] @product.selected_inventory = @inventory @properties = @product.selected_inventory.last.properties.to_h2 { |x| x.class.to_s.tableize } @cart_details = true render :action => :show end |
#update_quantity ⇒ Object
update quantity for item in cart
params[:quantity] = { "item_id" => "quantity }
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/opensteam/shopping_cart.rb', line 115 def update_quantity if request.post? params[:quantity].each { |key,value| @cart.set_quantity(key, value) } if session[:active_order] redirect_to :action => "show_cart" return end end redirect_to_index end |