Sha256: 6a353086168cf33c6b3619fedb65b75d024182506202601069469a9c683e2747
Contents?: true
Size: 1.45 KB
Versions: 5
Compression:
Stored size: 1.45 KB
Contents
module ActiveRecord module Acts module ShoppingCart module Item module InstanceMethods # # Returns the cart item for the specified object # def item_for(object) shopping_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
5 entries across 5 versions & 1 rubygems