Class: Item::Materials::CompatibleUpgrades

Inherits:
BaseCompatibleFinder
  • Object
show all
Defined in:
app/services/item/materials/compatible_upgrades.rb

Overview

This class is responsible for finding a catalog item's compatible controls

Instance Method Summary collapse

Instance Method Details

#process(item:, catalog_items_scope: nil) ⇒ Object

At a minimum you need an item
If you provide a catalog item scope, such as Catalog.catalog_items.for_online_catalog
It will be used to populate the catalog_items results
Without a catalog item scope only the items will be populated in the result



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/item/materials/compatible_upgrades.rb', line 8

def process(item:, catalog_items_scope: nil)
  items = Item.none
  catalog_items = CatalogItem.none
  messages = []

  items_by_direct_relation = Item.joins(:source_item_relations).merge(item.target_item_relations.upgrades.joins(:target_item)).order(:sku)

  if items_by_direct_relation.present?
    messages << "Upgrades discovered via target item relation"
    items = items_by_direct_relation
  elsif (item.is_towel_warmer_hardwired? || item.is_towel_warmer_dual_connect?) &&
      item.name =~ /riviera|infinity/i &&
      (bar_shape = item.spec_value(:bar_shape)) &&
      (finish = item.spec_value(:finish))
    messages << "Towel Warmer Hardwire finding compatible upgrades for #{bar_shape} / #{finish}"
      items = Item.by_product_line_path(LtreePaths::PL_TOWEL_WARMER_CRYSTAL_ACCESSORIES)
                  .by_product_category_path(LtreePaths::PC_UPGRADES)
                  .with_product_specification(:bar_shape, bar_shape, :appearance)
                  .with_product_specification(:finish, finish, :appearance).order(:sku)
  end

  return_results(item: item, items: items, catalog_items_scope: catalog_items_scope)

end