You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

14 rivejä
324 B

  1. class Cart < ApplicationRecord
  2. has_many :line_items, dependent: :destroy
  3. def add_product(product)
  4. current_item = line_items.find_by(product_id: product.id)
  5. if current_item
  6. current_item.quantity += 1
  7. else
  8. current_item = line_items.build(product_id: product.id)
  9. end
  10. current_item
  11. end
  12. end