Class: SpreeCmCommissioner::Integrations::VireakBuntham::Polling::SyncStockItem

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

Overview

SyncStockItem — creates/updates the stock item for a VET variant.

Uses schedule.seat_available (from VET’s ‘seatAvailable` field) to set count_on_hand.

Instance Method Summary collapse

Constructor Details

#initialize(sync_result:, vendor:) ⇒ SyncStockItem

Returns a new instance of SyncStockItem.



8
9
10
11
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_stock_item.rb', line 8

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

Instance Method Details

#call(variant:, schedule:) ⇒ Object

Parameters:



15
16
17
18
19
20
21
22
23
24
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/polling/sync_stock_item.rb', line 15

def call(variant:, schedule:)
  return unless variant&.persisted?

  stock_location = find_or_create_stock_location
  stock_item = variant.stock_items.find_or_create_by!(stock_location: stock_location) do |item|
    item.count_on_hand = 0
  end

  adjust_inventory_if_needed(stock_item, schedule.seat_available.to_i)
end