Class: Item::FloorPlanRetriever

Inherits:
BaseService show all
Defined in:
app/services/item/floor_plan_retriever.rb

Overview

Retrieves all the room configurations vignettes associated with a particular item.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Methods inherited from BaseService

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

Constructor Details

#initialize(options = {}) ⇒ FloorPlanRetriever

==== Initialization options (pass as a hash)

  • +:max_rooms+ - At max, return only this number of floorplans
    ==== Examples


14
15
16
# File 'app/services/item/floor_plan_retriever.rb', line 14

def initialize(options = {})
  super
end

Instance Method Details

#process(product_line) ⇒ Object

Retrieves all product specifications available to a given item

==== Parameters

  • +item+ - The item for which you want to retrieve floor plans

==== Returns

A Result object with

  • +all_rooms+ - an array of rooms


28
29
30
31
32
33
34
# File 'app/services/item/floor_plan_retriever.rb', line 28

def process(product_line)
  # all_rooms = []
  # all_rooms += rooms_with_floor_plans_for_item(item)
  # all_rooms = all_rooms.compact.uniq
  # all_rooms = all_rooms[0..(options[:max_rooms] - 1)] if options[:max_rooms]
  Result.new(all_rooms: showcases_floor_plans(product_line))
end

#showcases_floor_plans(product_line) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/services/item/floor_plan_retriever.rb', line 36

def showcases_floor_plans(product_line)
  return FloorPlanDisplay.none unless product_line

  pl_ids = [product_line.id]
  pl_ids += ProductLine.ancestors_ids(product_line.id)
  pl_ids += ProductLine.descendants_ids(product_line.id)
  pl_ids = pl_ids.compact.uniq

  base_scope = FloorPlanDisplay
               .joins(floor_plan_display_room_configurations: :room_configuration)
               .where(
                 'room_configurations.heating_system_product_line_id IN (:ids) OR room_configurations.quoted_heating_system_pl_id IN (:ids)',
                 ids: pl_ids
               )
               .preload(
                 :floor_plan_display_digital_assets,
                 { floor_plan_display_digital_assets: :digital_asset },
                 room_configurations: [
                   :floor_type,
                   :sub_floor_type,
                   :line_items,
                   { line_items: [:item, { item: [:successor_item, :orderable_view_product_catalogs] }] }
                 ]
               )
               .distinct
               .order(created_at: :desc)

  scope = base_scope.published
  scope = base_scope unless scope.exists? # fast check before falling back to any state

  scope = scope.limit(options[:max_rooms]) if options[:max_rooms]
  scope
end