class Order < ActiveRecord::Base
  belongs_to :user
  has_many :line_items, dependent: :destroy
  PAYMENT_TYPES = ["Check", "Credit Card", "Purchase Order"]
  validates :name, :email, :address, presence: true
  validates :pay_type, inclusion: PAYMENT_TYPES

  def add_line_items_from_cart(cart)
    cart.line_items.each do |item|
      item.cart_id = nil
      line_items << item
    end
  end

  validates :contact, presence: true
  validates :user_id, presence: true
end
