just a (hopefully) quick one today, apologies if it's super simple and I'm just thick.
I'm have a basic e-commerce app that I'm working on, and have 2 questions:
- I'd create a :product in admin with an amount of stock. I'm looking to automatically update the stock of a :product if one or more is added to someone's cart as a :cart_item, based on the quantity that they've got in their cart (even before checkout). So one update if a product is added, and another update if a customer changes quantity from the cart view.
- I'd like the name and price of :cart_item in a customers cart to be updated automatically if admin updates the associated :product.
Here are my model associations so far:
Customer
has_one :cart
has_many :orders
Product
has_many :cart_items
Cart
belongs_to:customer
has_many :cart_items
CartItem
belongs_to :product
belongs_to :cart
I only have scaffolds so far so all my current code is out of the box Rails 3.2.14.
I'm just not sure how to get the :cart_items to interact with the :products and vice versa. What code/extra functionality should I add to get this working? Thanks for the help.