Sha256: 5478d09fe2cc160f0dfe04a400fa314ece6123958f80852ede06202abac147c1

Contents?: true

Size: 635 Bytes

Versions: 2

Compression:

Stored size: 635 Bytes

Contents

module ActiveRecord
  module Acts
    module ShoppingCartItem
      module InstanceMethods
        #
        # Returns the subtotal, multiplying the quantity times the price of the item.
        #
        def subtotal
          format("%.2f", quantity * price).to_f
        end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_shopping_cart-0.4.1 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.4.0 lib/active_record/acts/shopping_cart_item/instance_methods.rb