app/models/unidom/order/order_item.rb in unidom-order-1.4.1 vs app/models/unidom/order/order_item.rb in unidom-order-1.4.2

- old
+ new

@@ -20,10 +20,13 @@ scope :order_is, ->(order) { where order_id: (order.respond_to?(:id) ? order.id : order) } scope :ordered_is, ->(ordered) { where ordered: ordered } scope :placed_by, ->(placer) { where placer: placer } + ## + # 订购商品 ordered ,放入订单 of 。订购者为 by ,缺省为订单的下单者。单价为 unit_price ,缺省值为 0 。数量为 quantity ,缺省值为 1。如: + # Unidom::Order::OrderItem.order! coca_cola, of: order, by: current_person, unit_price: 3.50, quantity: 2 def self.order!(ordered, of: nil, by: of.placer, unit_price: 0, quantity: 1) item = of.items.ordered_is(ordered).placed_by(by).valid_at.alive.first if item.present? item.quantity += quantity item.unit_price = unit_price @@ -34,6 +37,6 @@ ordinal = 1+of.items.valid_at.alive.maximum(:ordinal).to_i of.items.create! ordered: ordered, placer: by, ordinal: ordinal, quantity: quantity, unit_price: unit_price, purchase_amount: unit_price*quantity, subtotal_amount: unit_price*quantity, opened_at: Time.now end end -end +end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Order::OrderItem'