Class: Bodega::OrderProduct

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

Instance Method Summary collapse

Instance Method Details

#identifierObject



22
23
24
# File 'app/models/bodega/order_product.rb', line 22

def identifier
  "#{product_type}.#{product_id}"
end

#nameObject



26
27
28
# File 'app/models/bodega/order_product.rb', line 26

def name
  product.respond_to?(:name) ? product.name : "#{product_type.titleize} ##{product_id}"
end

#quantity_and_nameObject



37
38
39
# File 'app/models/bodega/order_product.rb', line 37

def quantity_and_name
  "#{quantity} x #{name.pluralize(quantity)}"
end

#subtotalObject



41
42
43
# File 'app/models/bodega/order_product.rb', line 41

def subtotal
  price * quantity
end

#update_stockObject



30
31
32
33
34
35
# File 'app/models/bodega/order_product.rb', line 30

def update_stock
  if keep_stock?
    product.number_in_stock = product.number_in_stock - quantity
    product.save(validate: false)
  end
end