Class: Unidom::Shopping::ShoppingCart
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- 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, unit_price, quantity = 1, opened_at = Time.now) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/models/unidom/shopping/shopping_cart.rb', line 17 def add!(shopped, unit_price, quantity = 1, opened_at = Time.now) item = items.shopped_is(shopped).valid_at.alive.first if item.present? item.attributes = { shopper: shopper, unit_price: unit_price, quantity: quantity+item.quantity } item.save! else items.create! shopped: shopped, shopper: shopper, unit_price: unit_price, quantity: quantity, opened_at: opened_at end end |