# Shopping carts model
class Cart < ApplicationRecord
  has_many :cart_products, -> { joins(:product).order('products.name ASC') }
  has_one :order

  def cart_value
    cart_products.sum('cart_products.price * cart_products.quantity')
  end
end
