| Class | Opensteam::ShoppingCart::Cart |
| In: |
lib/opensteam/shopping_cart.rb
|
| Parent: | Object |
| items | [RW] | cart_items |
intialize items array
# File lib/opensteam/shopping_cart.rb, line 213
213: def initialize
214: @items = []
215: end
delete item from cart (:cart_item_id or :yamlid )
# File lib/opensteam/shopping_cart.rb, line 271
271: def del( opts = {} )
272: if opts.has_key?( :yamlid )
273: @items.delete( get( :yamlid => opts[:yamlid] ) )
274: elsif opts.has_key?( :cart_item_id )
275: @items.delete_at( opts[:cart_item_id].to_i )
276: end
277: end
get item from cart
get( :cart_itemd_id => 1 ) # get item by internal array id get( :yamlid => 3 ) # get item by Inventory-id
# File lib/opensteam/shopping_cart.rb, line 223
223: def get( opts = {} )
224:
225: if opts.has_key? :yamlid
226: @items.each do |v|
227: return v if v.yamlid == opts[:yamlid]
228: end
229:
230: elsif opts.has_key? :cart_item_id
231: return @items[ opts[:cart_item_id].to_i ]
232: end
233:
234: return nil
235:
236: end
set quantity for item (by internal array-id)
# File lib/opensteam/shopping_cart.rb, line 254
254: def set_quantity( id, q )
255: item = @items[ id.to_i ]
256:
257: return nil if item.nil?
258:
259: q = q.to_i
260: if q == 0
261: @items.delete_at( id.to_i )
262: elsif q > 0
263: item.quantity = ( item.inventory.storage < q ) ? item.inventory.storage : q
264: end
265:
266: item
267: end