# frozen_string_literal: true # Cart class Cart < ApplicationRecord has_one :user_account, dependent: :destroy has_many :product_carts has_many :products, through: :product_carts def delete_product(product_id) relation = product_carts.find_by(product_id:, cart_id:) relation&.destroy end def add_product(product_id, quantity) product_carts.create(product_id:, quantity:) end end