Module: SpreeCmCommissioner::OrderIntegration
- Defined in:
- app/models/concerns/spree_cm_commissioner/order_integration.rb
Instance Method Summary collapse
-
#integration? ⇒ Boolean
Checks if any line item in this order has an integration (i.e., is from a vendor with an integration).
-
#restock_inventory_from_external_system! ⇒ Object
Attempts to restock inventory for all integration line items in this order.
-
#unstock_inventory_from_external_system! ⇒ Object
Attempts to unstock inventory for all integration line items in this order.
Instance Method Details
#integration? ⇒ Boolean
Checks if any line item in this order has an integration (i.e., is from a vendor with an integration). This is used to determine if inventory management operations should be delegated to an external system.
5 6 7 |
# File 'app/models/concerns/spree_cm_commissioner/order_integration.rb', line 5 def integration? line_items.any?(&:integration?) end |
#restock_inventory_from_external_system! ⇒ Object
Attempts to restock inventory for all integration line items in this order. Groups line items by vendor and delegates to the vendor’s integration service.
23 24 25 26 27 28 29 30 31 |
# File 'app/models/concerns/spree_cm_commissioner/order_integration.rb', line 23 def restock_inventory_from_external_system! integration_line_items = line_items.select(&:integration?) return if integration_line_items.empty? integration_line_items.group_by(&:vendor_id).each do |_, line_items| integration = line_items.first&.vendor&.integration integration.restock_external_inventory!(self, line_items) if integration.present? end end |
#unstock_inventory_from_external_system! ⇒ Object
Attempts to unstock inventory for all integration line items in this order. Groups line items by vendor and delegates to the vendor’s integration service.
11 12 13 14 15 16 17 18 19 |
# File 'app/models/concerns/spree_cm_commissioner/order_integration.rb', line 11 def unstock_inventory_from_external_system! integration_line_items = line_items.select(&:integration?) return if integration_line_items.empty? integration_line_items.group_by(&:vendor_id).each do |_, line_items| integration = line_items.first&.vendor&.integration integration.unstock_external_inventory!(self, line_items) if integration.present? end end |