Sha256: aac8cd46ea75d70f34f881de6b60805269e7808f638289949bef27e03a31d49e

Contents?: true

Size: 660 Bytes

Versions: 11

Compression:

Stored size: 660 Bytes

Contents

module ActiveRecord
  module Acts
    module ShoppingCartItem
      module InstanceMethods
        #
        # Returns the subtotal, multiplying the quantity times the price of the item.
        #
        def subtotal
          ("%.2f" % (self.quantity * self.price)).to_f
        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

11 entries across 11 versions & 1 rubygems

Version Path
acts_as_shopping_cart-0.3.0 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.2.2 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.2.1 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.2.0 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.1.6 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.1.5 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.1.4 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.1.3 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.1.2 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.1.1 lib/active_record/acts/shopping_cart_item/instance_methods.rb
acts_as_shopping_cart-0.1.0 lib/active_record/acts/shopping_cart_item/instance_methods.rb