Sha256: 50a5cbd92504273fb5f7655cc01931bc317cf01b3ff240cdd569d40c53c6a422
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
module ActiveRecord module Acts module ShoppingCart module Item module InstanceMethods # # Returns the cart item for the specified object # def item_for(object) cart_items.where(:item_id => object.id).first end # # Returns the subtotal of a specified item by multiplying the quantity times # the price of the item. # def subtotal_for(object) item = item_for(object) item ? item.subtotal : 0 end # # Returns the quantity of the specified object # def quantity_for(object) item = item_for(object) item ? item.quantity : 0 end # # Updates the quantity of the specified object # def update_quantity_for(object, new_quantity) item = item_for(object) item.update_quantity(new_quantity) if item end # # Returns the price of the specified object # def price_for(object) item = item_for(object) item ? item.price : 0 end # # Updates the price of the specified object # def update_price_for(object, new_price) item = item_for(object) item.update_price(new_price) if item end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_shopping_cart-0.1.0 | lib/active_record/acts/shopping_cart/item/instance_methods.rb |