Sha256: 692e4dcaecf3b859c6d47816f20edd3528635f268f54a39922feda213c833c49
Contents?: true
Size: 844 Bytes
Versions: 5
Compression:
Stored size: 844 Bytes
Contents
class CartItem < ActiveRecord::Base belongs_to :cart belongs_to :product delegate :name, :to => :product def increment_quantity(increment) self.quantity += increment end def quantity=(quantity) if quantity < 1 self.remove_from_cart! else write_attribute(:quantity, quantity) end end def shipping_weight self.product.shipping_weight * self.quantity end def remove_from_cart! self.destroy() end # Price per unit def unit_price ; self.product.price ; end def unit_pricef ; Cart.format_price(self.unit_price()) ; end # Total price def price ; self.product.price * self.quantity ; end def pricef ; Cart.format_price(self.price()) ; end # needed for rails magic form_for stuff, so DO NOT change this to some debug/display value def to_s self.product_id end end
Version data entries
5 entries across 5 versions & 1 rubygems