# == Schema Information # # Table name: carts # # id :bigint(8) not null, primary key # uuid :string(80) not null # ip :string(255) # useragent :string(255) # created_at :datetime # updated_at :datetime # # Shopping carts model class Cart < ApplicationRecord # == Constants ============================================================ # == Attributes =========================================================== # == Extensions =========================================================== # == Relationships ======================================================== has_many :cart_products, -> { joins(:product).order('products.name ASC') } has_one :order # == Validations ========================================================== # == Scopes =============================================================== # == Callbacks ============================================================ # == Class Methods ======================================================== # == Instance Methods ===================================================== def cart_value cart_products.sum('cart_products.price * cart_products.quantity') end end