Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Polling::SyncProduct
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::BookMeBusV1::Polling::SyncProduct
- Defined in:
- app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_product.rb
Overview
SyncProduct handles product synchronization for BookMeBus trips
This service is responsible for:
-
Creating or updating Product records from external trip data
-
Managing product attributes (name, status, pricing)
-
Handling integration mappings for products
Usage:
sync_service = SyncProduct.new(integration: integration, sync_result: sync_result)
product = sync_service.call(external_trip: external_trip, price: 10.0)
Instance Method Summary collapse
- #call(external_trip:, price:) ⇒ Object
-
#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/book_me_bus_v1/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(external_trip:, price:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_product.rb', line 20 def call(external_trip:, price:) external_id = "product-#{external_trip.trip_id}" 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(external_trip), 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: { trip_id: external_trip.trip_id }) product end |