Class: Edi::MiraklSeller::ProductDataProcessor
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::MiraklSeller::ProductDataProcessor
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/services/edi/mirakl_seller/product_data_processor.rb
Overview
Service object: product data processor.
Constant Summary
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Attributes inherited from BaseService
Instance Method Summary collapse
Methods inherited from BaseEdiService
#duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #report_order_creation_issues, #safe_process_edi_communication_log
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, #tagged_logger
Constructor Details
This class inherits a constructor from Edi::BaseEdiService
Instance Method Details
#load_results(_states: nil) ⇒ Object
45 46 47 48 49 50 |
# File 'app/services/edi/mirakl_seller/product_data_processor.rb', line 45 def load_results(_states: nil) catalog_items = CatalogItem.for_orchestrator_keys(orchestrator.config[:orchestrator_keys]) items = Item.where.not(upc: [nil, '']).joins(:catalog_items).merge(catalog_items).distinct { items: items, catalog_items: catalog_items } # CatalogItem.where(id: 46152) #This is a test catalog item end |
#process(_catalog_items: nil, _states: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/edi/mirakl_seller/product_data_processor.rb', line 7 def process(_catalog_items: nil, _states: nil) ecl = nil EdiCommunicationLog.transaction do logger.info "Sending product data for partner #{orchestrator.partner}" load_result = load_results items = load_result[:items] load_result[:catalog_items] data_result = orchestrator.product_data_configurator.build_xml(items: items) data_xml = data_result.xml # Always emit the ECL for the items that mapped so the sender has # something to upload; unmappable items are dropped, not the whole feed. ecl = EdiCommunicationLog.create_outbound_file_from_data( data: data_xml, file_extension: 'xml', file_name: "wy-api-product-export-#{Time.zone.now.strftime('%Y%m%d%H%M%S')}.xml", partner: orchestrator.partner, category: 'product_data', data_type: 'xml', file_info: {} ) # Intentional category skips (accessories, unmapped lines) are expected # on every run — log them, don't alarm anyone. if data_result.skipped.present? logger.info("[#{orchestrator.partner}] product_data excluded #{data_result.skipped.size} unmapped item(s): #{data_result.skipped.join('; ')}") end # Only a mapped product missing a *required* field is a genuine problem # (Mirakl will reject that product) — that's what warrants the alert. if data_result.errors.present? EdiMailer.notify_edi_admin_of_mirakl_error(orchestrator.partner, 'product_data', data_result.errors.join(" \n")).deliver_now end end ecl end |