Class: SpreeCmCommissioner::Integrations::Larryta::Polling::SyncProduct
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::Larryta::Polling::SyncProduct
- Defined in:
- app/services/spree_cm_commissioner/integrations/larryta/polling/sync_product.rb
Overview
SyncProduct handles product synchronization for Larryta schedules.
One Product per schedule per date (BookMeBus pattern). The external_id is “product-vendor_id-schedule_id-on_date” so each schedule/date combination gets its own Product with one Variant.
Product name format: “Phnom Penh → Siem Reap”
Usage:
product = SyncProduct.new(integration: integration, sync_result: sync_result)
.call(schedule: schedule, price: 13.0, on_date: "2026-03-30")
Instance Method Summary collapse
- #call(schedule:, price:, on_date:) ⇒ Spree::Product
-
#initialize(integration:, sync_result:) ⇒ SyncProduct
constructor
A new instance of SyncProduct.
Constructor Details
#initialize(integration:, sync_result:) ⇒ SyncProduct
Returns a new instance of SyncProduct.
14 15 16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_product.rb', line 14 def initialize(integration:, sync_result:) @integration = integration @sync_result = sync_result @vendor = @integration.vendor end |
Instance Method Details
#call(schedule:, price:, on_date:) ⇒ Spree::Product
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/polling/sync_product.rb', line 24 def call(schedule:, price:, on_date:) external_id = "product-#{@vendor.id}-#{schedule.id}-#{on_date}" mapping = Spree::Product.find_or_initialize_integration_mapping( integration_id: @integration.id, external_id: external_id ) product = mapping.internal @sync_result.track(:product, product) do |tracker| product.assign_attributes( name: build_product_name(schedule), short_name: build_short_name(schedule), status: :active, vendor: @vendor, product_type: :transit, available_on: Time.current, shipping_category: default_shipping_category, stores: [Spree::Store.default], option_types: [seat_type_option].compact, price: price ) tracker.save_if_changed!(product) end mapping.mark_as_active!(external_payload: { schedule_id: schedule.id, direction_id: schedule.direction_id }) product end |