summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-06 10:26:37 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-06 10:26:37 -0600
commit111e93744aceb8a61c06dfa4d2d843544b7b1078 (patch)
treec518de5d3b6bfcee7148daad659c69bedc3ab030
parente05709905db8834148c434d493344cc6f213a54b (diff)
Añadidos métodos de cart
-rw-r--r--app/models/cart.rb10
1 files changed, 10 insertions, 0 deletions
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