Module: ActiveRecord::Acts::ShoppingCartItem::InstanceMethods

Defined in:
lib/active_record/acts/shopping_cart_item/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#subtotalObject

Returns the subtotal, multiplying the quantity times the price of the item.



8
9
10
# File 'lib/active_record/acts/shopping_cart_item/instance_methods.rb', line 8

def subtotal
  format("%.2f", quantity * price).to_f
end

#update_price(new_price) ⇒ Object

Updates the price of the item



23
24
25
26
# File 'lib/active_record/acts/shopping_cart_item/instance_methods.rb', line 23

def update_price(new_price)
  self.price = new_price
  save
end

#update_quantity(new_quantity) ⇒ Object

Updates the quantity of the item



15
16
17
18
# File 'lib/active_record/acts/shopping_cart_item/instance_methods.rb', line 15

def update_quantity(new_quantity)
  self.quantity = new_quantity
  save
end