Module Opensteam::ShoppingCart::InstanceMethods
In: lib/opensteam/shopping_cart.rb

Methods

Public Instance methods

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

[Source]

    # File lib/opensteam/shopping_cart.rb, line 72
72:       def add_inventory_to_cart
73:         if request.post?
74:           
75:           params[:product] = frmt params[:product]
76:           
77:           if params[:product][:properties] && params[:product][:properties].index("")
78:             flash[:error] = "Please select a #{params[:product][:properties].index("").humanize}"
79:             return
80:           end
81:           
82:           product = Opensteam::Find.find_product_with_inventory( params[:product] )
83:           if product.is_available?
84:             unless @cart.add product.selected_inventories.last.id
85:               render :update do |page| page.alert "Sorry, there are only #{product.selected_inventories.last.storage} available!" end
86:             end
87:           else
88:             render :update do |page| page.alert "Sorry, this product is currently not available!" end
89:           end
90:         end
91:       end

[Source]

     # File lib/opensteam/shopping_cart.rb, line 113
113:       def decr_quantity
114:         if request.post?
115:           ( ( ci = @cart.get( :cart_item_id => params[:id] ) ).quantity - 1 ) == 0 ?
116:             @cart.items.delete_at( params[:id].to_i ) :
117:             ci.decr ;
118:         end
119:         if session[:active_order]
120:           render :template => "checkout/update_cart_content.rjs"
121:         else
122:           render :action => "add_inventory_to_cart.rjs"
123:         end
124:       end

delete item from cart

[Source]

    # File lib/opensteam/shopping_cart.rb, line 46
46:       def del_item
47:         get_cart.del( :cart_item_id => params[:id])
48:         @current_item = params[:id]
49:         redirect_to_index unless request.xhr?
50:       end

empty cart

[Source]

     # File lib/opensteam/shopping_cart.rb, line 151
151:       def empty_cart
152:         wipe_cart
153:         redirect_to_index
154:       end

[Source]

     # File lib/opensteam/shopping_cart.rb, line 96
 96:       def incr_quantity
 97:         if request.post?
 98:           ci = @cart.get( :cart_item_id => params[:id] )
 99:           unless ci.incr
100:             render :update do |page| page.alert "Sorry, there are only #{ci.quantity} available!" end
101:             return 
102:           end
103:         end
104:         if session[:active_order]
105:           render :template => "checkout/update_cart_content.rjs"
106:         else
107:           render :action => "add_inventory_to_cart.rjs"
108:         end
109:         
110:       end

show item from cart

[Source]

    # File lib/opensteam/shopping_cart.rb, line 55
55:       def show_cart_item
56:         i = Opensteam::InventoryBase::Inventory.find( @cart.items[ params[:id].to_i ].yamlid )
57:         @product = i.product
58:         @inventory = [i]
59:         @product.selected_inventory = @inventory
60:         @properties = @product.selected_inventory.last.properties.to_h2 { |x| x.class.to_s.tableize }
61:         @cart_details = true
62:         render :action => :show
63:       end

update quantity for item in cart

  params[:quantity] = { "item_id" => "quantity }

[Source]

     # File lib/opensteam/shopping_cart.rb, line 133
133:       def update_quantity
134:         if request.post?
135:           params[:quantity].each { |key,value| @cart.set_quantity(key, value) }
136:                         
137:           if session[:active_order]
138:             redirect_to :action => "show_cart"
139:             return
140:           end
141:         end
142:         redirect_to_index
143:       end

[Validate]