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 → stored only as the wayfair_retail_price reference
(a USD supplier figure, NOT the consumer price; never the retail_price column)
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 collapse
- WAYFAIR_PRODUCT_CODE_REGEXP =
The
WRM####product code trailing a Wayfair PDP path — the stable half
of a listing URL's identity. Wayfair's own codes carry more digits than
our WRM ones, hence\d{3,}rather than an exact width. Mirrors the regex
Retailer::Extractors::Wayfair#wayfair_sku_from_urluses for the same job. /-([A-Za-z]+\d{3,})\.html/i
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
-
#process(ecl, dry_run: false) ⇒ ProcessResult
Process an ECL containing Wayfair catalog data.
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, #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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/edi/wayfair/catalog_item_information_processor.rb', line 37 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 |