Class: Amazon::MatchBrowseNode

Inherits:
BaseService show all
Includes:
Memery
Defined in:
app/services/amazon/match_browse_node.rb

Overview

Processes Amazon catalog items and associates them with the appropriate Amazon browse nodes.

This service class is responsible for processing a set of Amazon catalog items, extracting the
relevant browse node IDs, and associating the catalog items with the corresponding browse nodes.
It handles cases where the catalog item already has associated browse nodes, as well as cases
where the browse node is missing or cannot be found.

param catalog_items [Array] the Amazon catalog items to process, active record relation
param logger [Logger] the logger to use for logging
param overwrite [Boolean] whether to overwrite existing browse node associations

Returns:

  • (Hash)

    a hash of processing results, keyed by catalog item ID

Instance Attribute Summary

Attributes inherited from BaseService

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Class Method Details

.process_amazon_catalog_items(catalog_items: nil, logger: Rails.logger, overwrite: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'app/services/amazon/match_browse_node.rb', line 16

def self.process_amazon_catalog_items(catalog_items: nil, logger: Rails.logger, overwrite: false)
  results = {}
  matcher = new(logger: logger)
  catalog_items ||= CatalogItem.amazons
  catalog_items.includes(:amazon_browse_nodes).find_each do |catalog_item|
    result = matcher.process(catalog_item, overwrite:)
    results.merge!(result)
  end
  results
end

Instance Method Details

#process(catalog_item, overwrite: false) ⇒ Object



27
28
29
30
31
32
33
34
# File 'app/services/amazon/match_browse_node.rb', line 27

def process(catalog_item, overwrite: false)
  return skip_existing_nodes(catalog_item) if catalog_item.amazon_browse_nodes.present? && !overwrite

  node_ids = extract_classification_ids(catalog_item.retailer_information)
  return handle_missing_data(catalog_item) if node_ids.blank?

  process_node(catalog_item, node_ids)
end