Class: Unidom::Shopping::ShoppingCart
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Unidom::Shopping::ShoppingCart
- Includes:
- Common::Concerns::ModelExtension
- Defined in:
- app/models/unidom/shopping/shopping_cart.rb
Overview
Shopping Cart 是购物车。
Instance Method Summary collapse
Instance Method Details
#add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/models/unidom/shopping/shopping_cart.rb', line 21 def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now) item = items.shopped_is(shopped).valid_at.alive.first if item.present? item.attributes = { shopper: by||shopper, unit_price: unit_price, quantity: quantity+item.quantity } item.save! else items.create! shopped: shopped, shopper: by||shopper, unit_price: unit_price, quantity: quantity, opened_at: at end end |