Class: Edi::Google::ProductDataProcessor
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::Google::ProductDataProcessor
- Defined in:
- app/services/edi/google/product_data_processor.rb
Overview
Builds one country's Google Merchant feed (the partner's catalog) as Merchant
API ProductInputs and stages it as a single outbound EdiCommunicationLog
for Sender.
Reuses Feed::Google::ListGenerator#load_products (the same scope +
valid_for_google? gate as the legacy XML feed) so the API push contains
exactly the products the fetch feed would, then maps each presenter through
Feed::Google::MerchantApi::ProductInputBuilder.
Constant Summary
Constants included from RequestIdentifiable
RequestIdentifiable::REQUEST_ID_HEADERS
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Attributes inherited from BaseService
Instance Method Summary collapse
-
#call ⇒ EdiCommunicationLog
The staged outbound feed (state
ready).
Methods inherited from BaseEdiService
#amazon_feed_product_type, #duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #onboard_ordered_catalog_items, #report_order_creation_issues, #safe_process_edi_communication_log
Methods included from RequestIdentifiable
Methods included from AddressAbbreviator
#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #process, #tagged_logger
Constructor Details
This class inherits a constructor from Edi::BaseEdiService
Instance Method Details
#call ⇒ EdiCommunicationLog
Returns the staged outbound feed (state ready).
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/edi/google/product_data_processor.rb', line 15 def call logger.info "Generating Google Merchant API product feed for #{orchestrator.partner}" catalog = Catalog.find(orchestrator.catalog_id) product_count = 0 data = +'[' I18n.with_locale(catalog.locale_for_catalog) do Feed::Google::ListGenerator.new.each_product(catalog) do |presenter| data << ',' if product_count.positive? data << JSON.generate(Feed::Google::MerchantApi::ProductInputBuilder.new(presenter).as_json) product_count += 1 end end data << ']' EdiCommunicationLog.create_outbound_file_from_data( data:, file_extension: 'json', partner: orchestrator.partner, category: 'product_data', data_type: 'json', file_info: { product_count:, feed_label: orchestrator.feed_label } ) end |