Class: Feed::ItemBaseGenerator

Inherits:
BaseService show all
Defined in:
app/services/feed/item_base_generator.rb

Direct Known Subclasses

ItemInventoryGenerator, ItemListGenerator

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Methods inherited from BaseService

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

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#append_xml_catalogs(xml, item) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/feed/item_base_generator.rb', line 24

def append_xml_catalogs(xml, item)
  xml.catalogs do
    # Use a select to not cause another N+1 query since we preloaded already
    item.catalog_items.preload({:store_item => [:store, :item]}, :catalog, :item).select(&:available_in_edi_feed?).each do |ci|
      xml.catalog do
        xml.id ci.catalog_id
        xml.catalog_item_id ci.id
        xml.country_iso3 ci.store_item.store.country_iso3
        xml.catalog_name ci.catalog.name
        xml.item_name ci.reported_name
        xml.tag! 'price', ci.amount, currency: ci.catalog.currency
        xml.retailer_part_number_label ci.catalog.retailer_part_number_label
        xml.third_party_part_number ci.third_party_part_number
        xml.quantity_available ci.store_item.qty_available
        if ci.catalog_id == 1
          xml.public_url "https://www.warmlyyours.com#{item.canonical_url(locale: 'en-US')}"
        elsif ci.catalog_id == 2
          xml.public_url "https://www.warmlyyours.com#{item.canonical_url(locale: 'en-CA')}"
        end
      end
    end
  end
end

#load_items(item_filters = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/feed/item_base_generator.rb', line 7

def load_items(item_filters = nil)
  items = Item.non_publications.packageable.public_and_active_in_any_catalogs.
                preload(:primary_product_line, :product_category, { store_items: [{ catalog_items: :catalog }, :store] }).
                order(:sku)
  items = items.where(item_filters) if item_filters.present?
  items = items.to_a

  pls = items.filter_map(&:primary_product_line).uniq(&:id)
  if pls.any?
    paths = ProductLine.canonical_paths_for(pls)
    pls.each { |pl| pl.instance_variable_set(:@canonical_path, paths[pl.id]) }
  end

  logger.info "Loaded #{items.size} items to generate product data"
  items.map { |i| Feed::ItemPresenter.new(i) }
end