Sha256: fb681e7d92912fe8c2a9be4a4d929d9642901a4d2f700fee472325b5b669bee3

Contents?: true

Size: 650 Bytes

Versions: 3

Compression:

Stored size: 650 Bytes

Contents

module ActiveRecord
  module Acts
    module ShoppingCartItem
      module InstanceMethods
        #
        # Returns the subtotal, multiplying the quantity times the price of the item.
        # 
        def subtotal
          self.quantity * self.price
        end

        #
        # Updates the quantity of the item
        #
        def update_quantity(new_quantity)
            self.quantity = new_quantity
            self.save
        end
        
        #
        # Updates the price of the item
        #
        def update_price(new_price)
            self.price = new_price
            self.save
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_shopping_cart-0.0.3 lib/active_record/acts/shopping_cart_item/cart_item_instance_methods.rb
acts_as_shopping_cart-0.0.2 lib/active_record/acts/shopping_cart_item/cart_item_instance_methods.rb
acts_as_shopping_cart-0.0.1 lib/active_record/acts/shopping_cart_item/cart_item_instance_methods.rb