Class: Workarea::MarkDiscountsAsRedeemed

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::CallbacksWorker, Sidekiq::Worker
Defined in:
app/workers/workarea/mark_discounts_as_redeemed.rb

Instance Method Summary collapse

Instance Method Details

#mark_redeemed(order, shippings) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/workers/workarea/mark_discounts_as_redeemed.rb', line 14

def mark_redeemed(order, shippings)
  discount_ids = order.discount_ids + shippings.map(&:discount_ids).flatten

  discount_ids.each do |applied_discount_id|
    discount = Pricing::Discount.find(applied_discount_id)
    discount.log_redemption(order.email)
    discount.touch
  end

  Pricing::Discount::GeneratedPromoCode
    .in(code: order.promo_codes.map(&:strip).map(&:downcase))
    .asc(:created_at)
    .uniq { |code| code.code_list_id.to_s }
    .each(&:used!)
end

#perform(order_id) ⇒ Object



8
9
10
11
12
# File 'app/workers/workarea/mark_discounts_as_redeemed.rb', line 8

def perform(order_id)
  order = Order.find(order_id)
  shippings = Shipping.where(order_id: order_id).to_a
  mark_redeemed(order, shippings)
end