Class: Www::SupportItemPresenter

Inherits:
BasePresenter
  • Object
show all
Includes:
Memery
Defined in:
app/presenters/www/support_item_presenter.rb

Delegated Instance Attributes collapse

Instance Method Summary collapse

Instance Method Details

#articlesObject



80
81
82
# File 'app/presenters/www/support_item_presenter.rb', line 80

def articles
  ArticleTechnical.published.for_product_line_url_with_ancestors(primary_product_line.slug_ltree.to_s).order(:subject)
end


29
30
31
32
33
# File 'app/presenters/www/support_item_presenter.rb', line 29

def breadcrumb
  bcs = support_product_line_presenter.breadcrumb_links
  bcs << { name: "#{sku}#{item.public_name}", url: nil }
  h.formatted_breadcrumb bcs
end

#cache_keyObject



9
10
11
# File 'app/presenters/www/support_item_presenter.rb', line 9

def cache_key
  "#{I18n.locale}/v4/#{item.cache_key}"
end

#can_be_purchased?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'app/presenters/www/support_item_presenter.rb', line 126

def can_be_purchased?
  product_catalog.present?
end

#display_faqs?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'app/presenters/www/support_item_presenter.rb', line 157

def display_faqs?
  faqs.present?
end

#documents(all_product_lines: false) ⇒ Object



59
60
61
# File 'app/presenters/www/support_item_presenter.rb', line 59

def documents(all_product_lines: false)
  retrieve_documents(all_product_lines:).all_publications
end

#documents_grouped_by_categoryObject



64
65
66
67
# File 'app/presenters/www/support_item_presenter.rb', line 64

def documents_grouped_by_category
  documents.sort_by { |d| [d.star? ? 0 : 1, d.featured_position.to_i, d.name.to_s] }
           .group_by(&:product_category_name)
end

#dynamic_introductionObject



161
162
163
164
165
166
167
168
169
170
171
# File 'app/presenters/www/support_item_presenter.rb', line 161

def dynamic_introduction
  str = 'This support page provides '
  contents = []
  contents += %w[publications manuals] if retrieve_documents.present?
  contents << 'specifications' if public_specifications.present?
  contents << 'videos' if videos_grouped.present?
  contents << 'support articles' if articles.present?
  contents << 'common support questions' if display_faqs?
  str << contents.to_sentence
  str
end

#faqsObject



85
86
87
# File 'app/presenters/www/support_item_presenter.rb', line 85

def faqs
  Item::ArticleRetriever.new(article_types: %w[faq], support: true, add_vote_data: true).process(item:).articles
end

#image_tag(options = {}) ⇒ Object



47
48
49
50
51
52
# File 'app/presenters/www/support_item_presenter.rb', line 47

def image_tag(options = {})
  return unless primary_image && primary_image.attachment_width > 300

  merged_options = options.merge({ width: 400, height: 400, background: 'ffffff' })
  h.image_asset_tag(primary_image, merged_options)
end

#last_sold_date_formattedObject



40
41
42
43
44
# File 'app/presenters/www/support_item_presenter.rb', line 40

def last_sold_date_formatted
  return unless (item.is_discontinued || !item.is_available_to_public?) && item.last_sale_date

  item.last_sale_date.strftime('%B %Y')
end

Alias for Product_catalog_presenter#notices_for_side_links

Returns:

  • (Object)

    Product_catalog_presenter#notices_for_side_links

See Also:



7
# File 'app/presenters/www/support_item_presenter.rb', line 7

delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true

#og_imageObject



25
26
27
# File 'app/presenters/www/support_item_presenter.rb', line 25

def og_image
  item.image_url2(size: '400x400')
end

#page_descriptionObject



17
18
19
# File 'app/presenters/www/support_item_presenter.rb', line 17

def page_description
  "Support page for #{item.effective_seo_title} - #{item.sku}. Installation guides, specifications, wiring diagrams, operation manuals and more. Provided by #{h.company_locale}"
end

#page_keywordsObject



21
22
23
# File 'app/presenters/www/support_item_presenter.rb', line 21

def page_keywords
  [sku, public_name, 'Support', 'Specifications', 'Documents', 'Videos', 'Manuals', 'Articles'].join(',')
end

#page_titleObject



13
14
15
# File 'app/presenters/www/support_item_presenter.rb', line 13

def page_title
  "#{sku} | Support | #{h.company_locale}"
end

#product_catalogObject



130
131
132
# File 'app/presenters/www/support_item_presenter.rb', line 130

def product_catalog
  @product_catalog ||= ViewProductCatalog.where(catalog_id: Catalog.locale_to_catalog_id).where(item_id: item.id).where(item_is_web_accessible: true).first
end

#product_catalog_presenterObject



134
135
136
137
138
# File 'app/presenters/www/support_item_presenter.rb', line 134

def product_catalog_presenter
  return nil unless product_catalog

  @product_catalog_presenter ||= Www::ProductCatalogPresenter.new(product_catalog, h)
end

#product_noticesObject

Alias for Product_catalog_presenter#product_notices

Returns:

  • (Object)

    Product_catalog_presenter#product_notices

See Also:



7
# File 'app/presenters/www/support_item_presenter.rb', line 7

delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true

#product_schemaObject



140
141
142
143
144
# File 'app/presenters/www/support_item_presenter.rb', line 140

def product_schema
  return nil unless product_catalog

  product_catalog_presenter&.schema_dot_org_structure
end

#public_specificationsObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/presenters/www/support_item_presenter.rb', line 90

def public_specifications
  # For kits we break specs down per component so visitors can compare each unit.
  # Exception: spare-parts kits (e.g. AK* parts kits) contain many small commodity
  # components whose individual specs (SKU, UPC, weight) are meaningless when listed
  # separately — show the kit-level specs instead.
  if is_kit? && !parts_kit?
    item.get_kit_items(spec_only: true).flat_map do |ki|
      ki.public_specifications.map do |s|
        s.grouping = "#{s.grouping} (#{ki.sku})"
        s
      end
    end
  else
    item.public_specifications
  end
end

#public_specifications_groupedObject



108
109
110
# File 'app/presenters/www/support_item_presenter.rb', line 108

def public_specifications_grouped
  public_specifications.sort_by(&:name).group_by(&:grouping)
end

#purchase_urlObject



146
147
148
149
150
# File 'app/presenters/www/support_item_presenter.rb', line 146

def purchase_url
  h.catalog_link(item)
rescue ArgumentError
  nil
end

rubocop:disable Lint/UnusedMethodArgument



119
120
121
122
123
# File 'app/presenters/www/support_item_presenter.rb', line 119

def related_items(include_self: false) # rubocop:disable Lint/UnusedMethodArgument
  r_items = []
  r_items += Item::Materials::CompatibleControls.new.process(item:, context: :support).items
  r_items + Item::Materials::CompatibleAccessories.new.process(item:, context: :support).items
end

#retrieve_documents(all_product_lines: false) ⇒ Object



54
55
56
# File 'app/presenters/www/support_item_presenter.rb', line 54

def retrieve_documents(all_product_lines: false)
  Item::PublicationRetriever.new.process(sku, categories: [:support], all_product_lines:)
end

#retrieve_videosObject



69
70
71
# File 'app/presenters/www/support_item_presenter.rb', line 69

def retrieve_videos
  Item::VideoRetriever.new(tags: 'for-support-page', ignore_individual_query_limits: true).process(item)
end

#sectionsObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'app/presenters/www/support_item_presenter.rb', line 177

def sections
  s = {}
  if show_notices_section?
    notices = product_notices
    s[:notices] = { title: 'Notices', counter: notices.size, partial: 'www/support_portals/section_notices', data: notices, fa_icon: 'info-circle' }
  end
  s[:faqs] = { title: 'Support Questions', counter: faqs.size, partial: 'www/support_portals/section_faqs', data: faqs, referral_sku: item.sku, pl: item.primary_product_line, fa_icon: 'question-mark' } if display_faqs?
  if retrieve_documents.present?
    s[:publications] = { title: 'Documents', counter: documents.size,
                         component: Www::SupportPublicationsComponent,
                         component_args: { publications_by_category: documents_grouped_by_category },
                         fa_icon: 'publication' }
  end
  if public_specifications.present?
    s[:specifications] = { title: 'Specifications', counter: public_specifications.size,
                           component: Www::SupportSpecificationsComponent,
                           component_args: { specifications_grouped: public_specifications_grouped },
                           fa_icon: 'specifications' }
  end
  s[:videos] = { title: 'Videos', counter: videos.size, partial: 'www/support_portals/section_videos', data: videos_grouped, pl: item.primary_product_line, fa_icon: 'video' } if videos_grouped.present?
  s[:articles] = { title: 'Articles', counter: articles.size, partial: 'www/support_portals/section_articles_links', data: articles, pl: item.primary_product_line, fa_icon: 'document' } if articles.present?
  if related_items.present?
    s[:related_items] = { title: 'Related Items', counter: related_items.size, partial: 'www/support_portals/section_related_items_with_images', data: related_items }
  end
  if sibling_items.present?
    partial = support_portal_should_use_images? ? 'www/support_portals/section_related_items_with_images' : 'www/support_portals/section_related_items'
    s[:sibling_items] = { title: 'Similar Items', counter: sibling_items.size, partial:, data: sibling_items }
  end
  s
end

#show_notices_section?Object

Alias for Product_catalog_presenter#show_notices_section?

Returns:

  • (Object)

    Product_catalog_presenter#show_notices_section?

See Also:



7
# File 'app/presenters/www/support_item_presenter.rb', line 7

delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true

#sibling_items(include_self: false) ⇒ Object



112
113
114
115
116
# File 'app/presenters/www/support_item_presenter.rb', line 112

def sibling_items(include_self: false)
  sibling_items = item_grouping_info(include_self:, context: :support)&.variants || Item.none
  sibling_items.non_publications.where(visible_for_support: true)
               .includes(:primary_image, :primary_product_line)
end

#support_introObject

Alias for Support_product_line_presenter#support_intro

Returns:

  • (Object)

    Support_product_line_presenter#support_intro

See Also:



6
# File 'app/presenters/www/support_item_presenter.rb', line 6

delegate :support_intro, to: :support_product_line_presenter

#support_portal_should_use_images?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'app/presenters/www/support_item_presenter.rb', line 173

def support_portal_should_use_images?
  primary_product_line&.support_portal_should_use_images
end

#support_product_line_presenterObject



152
153
154
# File 'app/presenters/www/support_item_presenter.rb', line 152

def support_product_line_presenter
  Www::SupportProductLinePresenter.new(item.primary_product_line, @view)
end

#titleObject



36
37
38
# File 'app/presenters/www/support_item_presenter.rb', line 36

def title
  item.public_name
end

#videosObject



74
75
76
# File 'app/presenters/www/support_item_presenter.rb', line 74

def videos
  retrieve_videos.all_videos
end

#videos_groupedObject

Alias for Retrieve_videos#videos_grouped

Returns:

  • (Object)

    Retrieve_videos#videos_grouped

See Also:



78
# File 'app/presenters/www/support_item_presenter.rb', line 78

delegate :videos_grouped, to: :retrieve_videos