Class: SpreeCmCommissioner::Integrations::Larryta::Polling::SyncVariant

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

Overview

SyncVariant handles variant synchronization for Larryta schedules.

One variant per product per date (BookMeBus pattern). The SKU uses vendor_id, schedule_id, and on_date.

SKU format: “variant-vendor_id-schedule_id-on_date” Example: “variant-42-516250-2026-03-30”

Usage:

variant = SyncVariant.new(sync_result: sync_result, vendor: vendor)
                     .call(product: product, schedule: schedule, price: 13.0, on_date: "2026-03-30")

Instance Method Summary collapse

Constructor Details

#initialize(sync_result:, vendor:) ⇒ SyncVariant

Returns a new instance of SyncVariant.



13
14
15
16
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_variant.rb', line 13

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

Instance Method Details

#call(product:, schedule:, price:, on_date:) ⇒ Spree::Variant

Parameters:

  • product (Spree::Product)
  • schedule (Resources::Schedule)
  • price (Numeric)
  • on_date (String)

    YYYY-MM-DD sync date

Returns:

  • (Spree::Variant)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_variant.rb', line 23

def call(product:, schedule:, price:, on_date:)
  sku = build_variant_sku(schedule, on_date)
  variant = product.variants.find_by(sku: sku) || product.variants.build(sku: sku)

  @sync_result.track(:variant, variant) do |tracker|
    variant.assign_attributes(
      vendor: @vendor,
      price: price,
      track_inventory: true,
      product_type: :transit,
      option_values: [default_option_value],
      manual_generate_inventory_items: true
    )
    tracker.save_if_changed!(variant)
  end

  variant
end