From 111e93744aceb8a61c06dfa4d2d843544b7b1078 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 6 Apr 2023 10:26:37 -0600 Subject: Añadidos métodos de cart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/cart.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/models') diff --git a/app/models/cart.rb b/app/models/cart.rb index 4bccd67..996d107 100644 --- a/app/models/cart.rb +++ b/app/models/cart.rb @@ -5,4 +5,14 @@ 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 -- cgit v1.2.3