Module: Spree::OrderDecorator
- Defined in:
- app/models/spree/order_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_group_buy ⇒ Object
- #deliver_groupbuy_order_confirmation_email ⇒ Object
- #finalize! ⇒ Object
- #is_group_buy? ⇒ Boolean
-
#process_payments! ⇒ Object
if it is group buy order then just authorize, otherwise purchase.
- #update_line_item_prices! ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
3 4 5 |
# File 'app/models/spree/order_decorator.rb', line 3 def self.prepended(base) base.whitelisted_ransackable_attributes = %w[completed_at email number state payment_state shipment_state total considered_risky group_buy channel] end |
Instance Method Details
#check_group_buy ⇒ Object
47 48 49 |
# File 'app/models/spree/order_decorator.rb', line 47 def check_group_buy update_column(:group_buy, is_group_buy?) end |
#deliver_groupbuy_order_confirmation_email ⇒ Object
42 43 44 45 |
# File 'app/models/spree/order_decorator.rb', line 42 def deliver_groupbuy_order_confirmation_email Spree::OrderMailer.groupbuy_confirm_email(id).deliver_later update_column(:confirmation_delivered, true) end |
#finalize! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/spree/order_decorator.rb', line 16 def finalize! # lock all adjustments (coupon promotions, etc.) all_adjustments.each(&:close) # update payment and shipment(s) states, and save updater.update_payment_state shipments.each do |shipment| shipment.update!(self) shipment.finalize! end updater.update_shipment_state save! updater.run_hooks touch :completed_at if group_buy deliver_groupbuy_order_confirmation_email unless confirmation_delivered? else deliver_order_confirmation_email unless confirmation_delivered? end consider_risk end |
#is_group_buy? ⇒ Boolean
51 52 53 54 55 56 |
# File 'app/models/spree/order_decorator.rb', line 51 def is_group_buy? line_items.each do |line_item| return true if line_item.group_buy_id? end return false end |
#process_payments! ⇒ Object
if it is group buy order then just authorize, otherwise purchase
59 60 61 62 63 64 65 |
# File 'app/models/spree/order_decorator.rb', line 59 def process_payments! if group_buy process_payments_with(:authorize!) else process_payments_with(:purchase!) end end |
#update_line_item_prices! ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'app/models/spree/order_decorator.rb', line 7 def update_line_item_prices! transaction do line_items.reload.each(&:update_price) save! end check_group_buy end |