Sha256: f5968c717399a661091787a94f922c992b0868cbb8d925501c9c8e36566d7af4
Contents?: true
Size: 878 Bytes
Versions: 8
Compression:
Stored size: 878 Bytes
Contents
# Shopping Cart 是购物车。 class Unidom::Shopping::ShoppingCart < ActiveRecord::Base self.table_name = 'unidom_shopping_carts' include Unidom::Common::Concerns::ModelExtension belongs_to :shopper, polymorphic: true belongs_to :shop, polymorphic: true has_many :items, class_name: 'Unidom::Shopping::ShoppingItem' scope :shopped_by, ->(shopper) { where shopper: shopper } scope :shop_is, ->(shop) { where shop: shop } 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 end
Version data entries
8 entries across 8 versions & 1 rubygems