Class: Edi::Amazon::ProductDataProcessor
- Inherits:
-
BaseEdiService
- Object
- BaseService
- BaseEdiService
- Edi::Amazon::ProductDataProcessor
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/services/edi/amazon/product_data_processor.rb
Constant Summary
Constants included from Edi::AddressAbbreviator
Edi::AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary
Attributes inherited from BaseEdiService
Instance Method Summary collapse
- #append_catalog_items(xml, catalog_items) ⇒ Object
- #build_xml(catalog_items: nil, states: nil) ⇒ Object
- #load_catalog_items(states: nil) ⇒ Object
- #process(catalog_items: nil, states: nil) ⇒ Object
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 Edi::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
#append_catalog_items(xml, catalog_items) ⇒ Object
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 75 76 77 78 |
# File 'app/services/edi/amazon/product_data_processor.rb', line 45 def append_catalog_items(xml, catalog_items) idx = 0 catalog_items.find_each do |ci| xml.send(:Message) do xml.send(:MessageID, idx += 1) xml.send(:OperationType, 'Update') xml.send(:Product) do xml.send(:SKU, ci.reported_vendor_sku) xml.send(:ItemPackageQuantity, 1) xml.send(:DescriptionData) do # xml.send(:Title, ci.title_for_amazon) Don't come near the title xml.send(:PackageDimensions) do xml.send(:Length, unitOfMeasure: 'IN') do xml.text(ci.item.shipping_length.ceil) end xml.send(:Width, unitOfMeasure: 'IN') do xml.text(ci.item.shipping_width.ceil) end xml.send(:Height, unitOfMeasure: 'IN') do xml.text(ci.item.shipping_height.ceil) end end xml.send(:PackageWeight, unitOfMeasure: 'LB') do xml.text(ci.item.shipping_weight.ceil) end xml.send(:ShippingWeight, unitOfMeasure: 'LB') do xml.text(ci.item.shipping_weight.ceil) end end end end end xml end |
#build_xml(catalog_items: nil, states: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/edi/amazon/product_data_processor.rb', line 29 def build_xml(catalog_items: nil, states: nil) catalog_items ||= load_catalog_items(states:) logger.info "#{catalog_items.size} items in price payload" b = Nokogiri::XML::Builder.new do |xml| xml.send(:AmazonEnvelope, 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:noNamespaceSchemaLocation': 'amzn-envelope.xsd') do xml.send(:Header) do xml.send(:DocumentVersion, '1.01') xml.send(:MerchantIdentifier, orchestrator.merchant_id) end xml.send(:MessageType, 'Product') append_catalog_items(xml, catalog_items) end end b.to_xml end |
#load_catalog_items(states: nil) ⇒ Object
24 25 26 27 |
# File 'app/services/edi/amazon/product_data_processor.rb', line 24 def load_catalog_items(states: nil) states ||= %w[active active_hidden require_vendor_update pending_vendor_update pending_discontinue] orchestrator.customer.catalog.catalog_items.where(state: states).amazons_with_asins end |
#process(catalog_items: nil, states: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/edi/amazon/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}" catalog_items ||= load_catalog_items(states:) data_xml = build_xml(catalog_items:, states:) ecl = EdiCommunicationLog.create_outbound_file_from_data( data: data_xml, file_extension: 'pri', partner: orchestrator.partner, category: 'product_data', file_info: {} ) end ecl end |