Class: Pricing::DiscountLevelChangedHandler

Inherits:
ApplicationJob
  • Object
show all
Includes:
RailsEventStore::AsyncHandler
Defined in:
app/subscribers/pricing/discount_level_changed_handler.rb

Constant Summary collapse

OPEN_QUOTE_STATES_EXCLUDED =
%w[complete cancelled].freeze
OPEN_ORDER_STATES =
%w[cart pending pending_payment in_cr_hold].freeze
REPRICEABLE_ORDER_TYPES =
[Order::SALES_ORDER, Order::MARKETING_ORDER, Order::TECH_ORDER].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call_for(customer) ⇒ Object



23
24
25
# File 'app/subscribers/pricing/discount_level_changed_handler.rb', line 23

def self.call_for(customer)
  new.process(customer)
end

Instance Method Details

#perform(event) ⇒ Object



27
28
29
30
31
32
# File 'app/subscribers/pricing/discount_level_changed_handler.rb', line 27

def perform(event)
  customer = Customer.find_by(id: event.data[:customer_id])
  return unless customer

  process(customer)
end

#process(customer) ⇒ Object



34
35
36
37
38
39
# File 'app/subscribers/pricing/discount_level_changed_handler.rb', line 34

def process(customer)
  Rails.logger.info "Customer #{customer.id} -- Discount change detected, propagating"
  open_itemizables(customer).each do |itemizable|
    ItemizableDiscountResetWorker.perform_async(itemizable.class.name, itemizable.id)
  end
end