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



91
92
93
# File 'app/presenters/www/support_item_presenter.rb', line 91

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


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

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

#cache_keyObject



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

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

#can_be_purchased?Boolean

Returns:

  • (Boolean)


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

def can_be_purchased?
  product_catalog.present?
end

#display_faqs?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'app/presenters/www/support_item_presenter.rb', line 168

def display_faqs?
  faqs.present?
end

#documents(all_product_lines: false) ⇒ Object



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

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

#documents_grouped_by_categoryObject



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

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



172
173
174
175
176
177
178
179
180
# File 'app/presenters/www/support_item_presenter.rb', line 172

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



96
97
98
# File 'app/presenters/www/support_item_presenter.rb', line 96

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

#image_tag(options = {}) ⇒ String?

Image tag for the support item's primary image, constrained to
400x400 on a white background.

Parameters:

  • options (Hash) (defaults to: {})

    options forwarded to image_asset_tag

Options Hash (options):

  • :width (Integer)

    image width (merged with 400)

  • :height (Integer)

    image height (merged with 400)

  • :background (String)

    background color ('ffffff')

Returns:

  • (String, nil)

    HTML tag, or nil without a large enough image



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

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



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

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:



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

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

#og_imageObject



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

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

#page_descriptionObject



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

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



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

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

#page_titleObject



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

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

#product_catalogObject



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

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



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

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:



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

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

#product_schemaObject



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

def product_schema
  return nil unless product_catalog

  product_catalog_presenter&.schema_dot_org_structure
end

#public_specificationsObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/presenters/www/support_item_presenter.rb', line 101

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



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

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

#purchase_urlObject



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

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

rubocop:disable Lint/UnusedMethodArgument



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

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



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

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

#retrieve_videosObject



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

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

#sectionsObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'app/presenters/www/support_item_presenter.rb', line 186

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:



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

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

#sibling_items(include_self: false) ⇒ Object



123
124
125
126
127
# File 'app/presenters/www/support_item_presenter.rb', line 123

def sibling_items(include_self: false)
  sibling_items = item_grouping_info(include_self:)&.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:



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

delegate :support_intro, to: :support_product_line_presenter

#support_portal_should_use_images?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'app/presenters/www/support_item_presenter.rb', line 182

def support_portal_should_use_images?
  primary_product_line&.support_portal_should_use_images
end

#support_product_line_presenterObject



163
164
165
# File 'app/presenters/www/support_item_presenter.rb', line 163

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

#titleObject



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

def title
  item.public_name
end

#videosObject



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

def videos
  retrieve_videos.all_videos
end

#videos_groupedObject

Alias for Retrieve_videos#videos_grouped

Returns:

  • (Object)

    Retrieve_videos#videos_grouped

See Also:



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

delegate :videos_grouped, to: :retrieve_videos