Class: CartItem

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cart_item.rb

Instance Method Summary collapse

Instance Method Details

#increment_quantity(increment) ⇒ Object



7
8
9
# File 'app/models/cart_item.rb', line 7

def increment_quantity(increment)
  self.quantity += increment
end

#priceObject

Total price



32
# File 'app/models/cart_item.rb', line 32

def price  ; self.product.price * self.quantity ; end

#pricefObject



33
# File 'app/models/cart_item.rb', line 33

def pricef ; Cart.format_price(self.price()) ; end

#quantity=(quantity) ⇒ Object



11
12
13
14
15
16
17
# File 'app/models/cart_item.rb', line 11

def quantity=(quantity)
  if quantity < 1
    self.remove_from_cart!
  else
    write_attribute(:quantity, quantity)
  end
end

#remove_from_cart!Object



23
24
25
# File 'app/models/cart_item.rb', line 23

def remove_from_cart!
  self.destroy()
end

#shipping_weightObject



19
20
21
# File 'app/models/cart_item.rb', line 19

def shipping_weight
  self.product.shipping_weight * self.quantity
end

#to_sObject

needed for rails magic form_for stuff, so DO NOT change this to some debug/display value



36
37
38
# File 'app/models/cart_item.rb', line 36

def to_s
  self.product_id
end

#unit_priceObject

Price per unit



28
# File 'app/models/cart_item.rb', line 28

def unit_price  ; self.product.price ; end

#unit_pricefObject



29
# File 'app/models/cart_item.rb', line 29

def unit_pricef ; Cart.format_price(self.unit_price()) ; end