Class: SpreeCmCommissioner::Integrations::Larryta::Polling::SyncStockItem

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/larryta/polling/sync_stock_item.rb

Overview

SyncStockItem handles stock level synchronization for Larryta schedules.

Uses ‘schedule.total_available` (from the get_schedules response) as the authoritative seat count. Adjusts the StockItem’s count_on_hand if it differs from the current value.

This service does NOT create InventoryItems — those are generated daily by SpreeCmCommissioner::Stock::PermanentInventoryItemsGeneratorJob.

Usage:

SyncStockItem.new(sync_result: sync_result, vendor: vendor)
            .call(variant: variant, schedule: schedule)

Instance Method Summary collapse

Constructor Details

#initialize(sync_result:, vendor:) ⇒ SyncStockItem

Returns a new instance of SyncStockItem.



15
16
17
18
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_stock_item.rb', line 15

def initialize(sync_result:, vendor:)
  @sync_result = sync_result
  @vendor = vendor
end

Instance Method Details

#call(variant:, schedule:) ⇒ Object

Parameters:



22
23
24
25
26
27
28
29
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_stock_item.rb', line 22

def call(variant:, schedule:)
  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, schedule)
end