Class: Item::Materials::BaseCompatibleFinder

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/item/materials/base_compatible_finder.rb

Overview

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

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.intersecing_product_lind_ids(main_element, add_on_element) ⇒ Object



19
20
21
22
# File 'app/services/item/materials/base_compatible_finder.rb', line 19

def self.intersecing_product_lind_ids(main_element, add_on_element)
  intersecting_pl_ids = (main_element.product_line_ids_constellation & ProductLine.self_and_descendants_ids(*add_on_element.product_line_ids))
  intersecting_pl_ids.compact.uniq
end

Instance Method Details

#return_results(item:, items: Item.none, catalog_items_scope: nil) ⇒ Object (protected)



10
11
12
13
14
15
16
17
# File 'app/services/item/materials/base_compatible_finder.rb', line 10

def return_results(item:, items: Item.none, catalog_items_scope: nil)
  catalog_items = CatalogItem.none
  items = items.where.not(id: item.id) #exclude self
  if catalog_items_scope
    catalog_items = catalog_items_scope.joins(:store_item).where(store_items: { item_id: items.pluck(:id)})
  end
  Result.new(items: items, catalog_items: catalog_items, item: item)
end