Class: Edi::Wayfair::CatalogItemInformationProcessor
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::Wayfair::CatalogItemInformationProcessor
- Defined in:
- app/services/edi/wayfair/catalog_item_information_processor.rb
Overview
Processes catalog item information retrieved from the Wayfair Supplier Catalog API
Updates CatalogItem records with Wayfair-specific identifiers:
Field Mapping:
- productId → basis for third_party_part_number (with W prefix)
- skus[].displaySku → third_party_sku (the customer-facing Wayfair SKU like "W001498355")
- skus[].retailPrice → used for price comparison
This enables better product identity validation for retailer probes
and ensures correct URL construction for the Wayfair storefront.
Defined Under Namespace
Classes: ProcessResult
Constant Summary
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Instance Method Summary collapse
-
#process(ecl, dry_run: false) ⇒ ProcessResult
Process an ECL containing Wayfair catalog data.
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, #options, #tagged_logger
Constructor Details
This class inherits a constructor from Edi::BaseEdiService
Instance Method Details
#process(ecl, dry_run: false) ⇒ ProcessResult
Process an ECL containing Wayfair catalog data
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 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/services/edi/wayfair/catalog_item_information_processor.rb', line 23 def process(ecl, dry_run: false) return ProcessResult.new(processed: 0, skipped: 0, errors: ['ECL data is blank'], catalog_items_updated: []) if ecl&.data.blank? json_hash = JSON.parse(ecl.data).with_indifferent_access products = json_hash.dig(:data, :supplierCatalog, :products) || [] processed = 0 skipped = 0 errors = [] catalog_items_updated = [] catalog = orchestrator.customer&.catalog return ProcessResult.new(processed: 0, skipped: 0, errors: ['No catalog found for orchestrator customer'], catalog_items_updated: []) unless catalog products.each do |product_data| result = process_product(product_data, catalog, dry_run: dry_run) case result[:status] when :processed processed += 1 catalog_items_updated << result[:catalog_item] if result[:catalog_item] when :skipped skipped += 1 when :error errors << result[:message] end end # Link ECL to updated catalog items unless dry_run catalog_items_updated.each do |catalog_item| ecl.edi_documents.find_or_create_by(catalog_item: catalog_item) end ecl.complete! if ecl.can_complete? && errors.empty? end ProcessResult.new(processed: processed, skipped: skipped, errors: errors, catalog_items_updated: catalog_items_updated) end |