Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Polling::SyncInventory
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::BookMeBusV1::Polling::SyncInventory
- Defined in:
- app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_inventory.rb
Overview
SyncInventory handles inventory synchronization for BookMeBus trips
This service is responsible for:
-
Creating or updating StockItem records
-
Adjusting inventory counts based on external seat availability
-
Managing stock locations for vendors
Usage:
sync_service = SyncInventory.new(sync_result: sync_result, vendor: vendor)
sync_service.call(variant: variant, external_trip: external_trip)
Instance Method Summary collapse
- #call(variant:, external_trip:) ⇒ Object
-
#initialize(sync_result:, vendor:) ⇒ SyncInventory
constructor
A new instance of SyncInventory.
Constructor Details
#initialize(sync_result:, vendor:) ⇒ SyncInventory
Returns a new instance of SyncInventory.
14 15 16 17 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_inventory.rb', line 14 def initialize(sync_result:, vendor:) @sync_result = sync_result @vendor = vendor end |
Instance Method Details
#call(variant:, external_trip:) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_inventory.rb', line 19 def call(variant:, external_trip:) return unless variant&.persisted? stock_location = find_or_create_stock_location stock_item = find_or_create_stock_item(variant, stock_location) adjust_inventory_if_needed(stock_item, external_trip) end |