Class: Delivery::ApplySelectedShippingCost
- Inherits:
-
BaseService
- Object
- BaseService
- Delivery::ApplySelectedShippingCost
- Defined in:
- app/services/delivery/apply_selected_shipping_cost.rb
Overview
Centralized application of a selected ShippingCost to a delivery and its
shipping LineItem — ensures consistency whether the selection was
auto-computed (SetProperShippingCost) or explicitly chosen
(cart shipping picker, CRM shipping-method update).
Syncs the shipping line (item, price, description, discount reset), the
delivery's selection columns, and pushes the carrier down onto every
shipment. With persist: true the delivery columns are written via
update_columns (no callbacks) and the shipping line is saved immediately;
otherwise everything stays in-memory for the caller's save.
Extracted from Delivery#apply_selected_shipping_cost! (god-object
decomposition); the model keeps a thin delegator.
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#initialize(delivery, shipping_cost_entry, previous_selected_id: nil, persist: false) ⇒ ApplySelectedShippingCost
constructor
A new instance of ApplySelectedShippingCost.
- #process ⇒ void
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger
Constructor Details
#initialize(delivery, shipping_cost_entry, previous_selected_id: nil, persist: false) ⇒ ApplySelectedShippingCost
Returns a new instance of ApplySelectedShippingCost.
22 23 24 25 26 27 28 |
# File 'app/services/delivery/apply_selected_shipping_cost.rb', line 22 def initialize(delivery, shipping_cost_entry, previous_selected_id: nil, persist: false) super() @delivery = delivery @entry = shipping_cost_entry @previous_selected_id = previous_selected_id @persist = persist end |
Instance Method Details
#process ⇒ void
This method returns an undefined value.
33 34 35 36 37 38 39 40 41 |
# File 'app/services/delivery/apply_selected_shipping_cost.rb', line 33 def process guard_option_item! shipping_line = sync_shipping_line! sync_delivery_fields! propagate_carrier_to_shipments! persist_or_prune!(shipping_line) reset_resource_totals! Rails.logger.debug { "apply_selected_shipping_cost!, after: shipping_line: #{shipping_line.inspect}" } end |