Class: OrderCustomerDefaultsApplier

Inherits:
Object
  • Object
show all
Defined in:
app/services/order_customer_defaults_applier.rb

Overview

Applies the same set of customer-derived defaults to a new Order regardless
of whether the entry point is a Customer (customer.orders.new) or a Contact
(contact.orders.new). Centralizes the historical duplication between
CustomerPricing#set_default_for_order and
ContactDeactivationAndDefaults#set_default_for_order.

Flat name required because Order is an AR model (Zeitwerk).

Usage:
OrderCustomerDefaultsApplier.call(order: new_order, customer: self) # from Customer
OrderCustomerDefaultsApplier.call(order: new_order, customer: customer, contact: self) # from Contact

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order:, customer:, contact: nil) ⇒ OrderCustomerDefaultsApplier

Returns a new instance of OrderCustomerDefaultsApplier.



19
20
21
22
23
# File 'app/services/order_customer_defaults_applier.rb', line 19

def initialize(order:, customer:, contact: nil)
  @order = order
  @customer = customer
  @contact = contact
end

Class Method Details

.call(order:, customer:, contact: nil) ⇒ Object



15
16
17
# File 'app/services/order_customer_defaults_applier.rb', line 15

def self.call(order:, customer:, contact: nil)
  new(order: order, customer: customer, contact: contact).call
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
# File 'app/services/order_customer_defaults_applier.rb', line 25

def call
  apply_pricing_and_program_fields
  apply_currency_and_buying_group
  apply_shipping_fields_unless_cart
  apply_party_links
  @order
end