Class: Www::SupportItemPresenter

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

Overview

Presenter: support item presenter.

Delegated Instance Attributes collapse

Instance Method Summary collapse

Instance Method Details

#articlesObject



82
83
84
# File 'app/presenters/www/support_item_presenter.rb', line 82

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


31
32
33
34
35
# File 'app/presenters/www/support_item_presenter.rb', line 31

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

#cache_keyObject



11
12
13
# File 'app/presenters/www/support_item_presenter.rb', line 11

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

#can_be_purchased?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'app/presenters/www/support_item_presenter.rb', line 128

def can_be_purchased?
  product_catalog.present?
end

#display_faqs?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'app/presenters/www/support_item_presenter.rb', line 159

def display_faqs?
  faqs.present?
end

#documents(all_product_lines: false) ⇒ Object



61
62
63
# File 'app/presenters/www/support_item_presenter.rb', line 61

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

#documents_grouped_by_categoryObject



66
67
68
69
# File 'app/presenters/www/support_item_presenter.rb', line 66

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



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

def dynamic_introduction
  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?
  "This support page provides #{contents.to_sentence}"
end

#faqsObject



87
88
89
# File 'app/presenters/www/support_item_presenter.rb', line 87

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

#image_tag(options = {}) ⇒ Object



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

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



42
43
44
45
46
# File 'app/presenters/www/support_item_presenter.rb', line 42

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:



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

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

#og_imageObject



27
28
29
# File 'app/presenters/www/support_item_presenter.rb', line 27

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

#page_descriptionObject



19
20
21
# File 'app/presenters/www/support_item_presenter.rb', line 19

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



23
24
25
# File 'app/presenters/www/support_item_presenter.rb', line 23

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

#page_titleObject



15
16
17
# File 'app/presenters/www/support_item_presenter.rb', line 15

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

#product_catalogObject



132
133
134
# File 'app/presenters/www/support_item_presenter.rb', line 132

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



136
137
138
139
140
# File 'app/presenters/www/support_item_presenter.rb', line 136

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:



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

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

#product_schemaObject



142
143
144
145
146
# File 'app/presenters/www/support_item_presenter.rb', line 142

def product_schema
  return nil unless product_catalog

  product_catalog_presenter&.schema_dot_org_structure
end

#public_specificationsObject



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

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



110
111
112
# File 'app/presenters/www/support_item_presenter.rb', line 110

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

#purchase_urlObject



148
149
150
151
152
# File 'app/presenters/www/support_item_presenter.rb', line 148

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

rubocop:disable Lint/UnusedMethodArgument



121
122
123
124
125
# File 'app/presenters/www/support_item_presenter.rb', line 121

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



56
57
58
# File 'app/presenters/www/support_item_presenter.rb', line 56

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

#retrieve_videosObject



71
72
73
# File 'app/presenters/www/support_item_presenter.rb', line 71

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
# 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?
  s[:related_items] = { title: 'Related Items', counter: related_items.size, partial: 'www/support_portals/section_related_items_with_images', data: related_items } if related_items.present?
  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:



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

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

#sibling_items(include_self: false) ⇒ Object



114
115
116
117
118
# File 'app/presenters/www/support_item_presenter.rb', line 114

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:



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

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



154
155
156
# File 'app/presenters/www/support_item_presenter.rb', line 154

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

#titleObject



38
39
40
# File 'app/presenters/www/support_item_presenter.rb', line 38

def title
  item.public_name
end

#videosObject



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

def videos
  retrieve_videos.all_videos
end

#videos_groupedObject

Alias for Retrieve_videos#videos_grouped

Returns:

  • (Object)

    Retrieve_videos#videos_grouped

See Also:



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

delegate :videos_grouped, to: :retrieve_videos