Class: Feed::Google::GoogleProductPresenter
- Inherits:
-
Www::ProductCatalogPresenter
- Object
- Www::ProductCatalogPresenter
- Feed::Google::GoogleProductPresenter
show all
- Includes:
- Memery
- Defined in:
- app/services/feed/google/google_product_presenter.rb
Overview
Service object: google product presenter.
Delegated Instance Attributes
collapse
Instance Method Summary
collapse
Instance Method Details
#additional_image_links ⇒ Object
51
52
53
|
# File 'app/services/feed/google/google_product_presenter.rb', line 51
def additional_image_links
(all_images(max_images: 10) || []).map { |i| i.image_url(encode_format: :webp, width: 1280) }
end
|
#all_images(max_images: nil) ⇒ Object
41
42
43
44
|
# File 'app/services/feed/google/google_product_presenter.rb', line 41
def all_images(max_images: nil)
images = item.image_profiles.website_image_profiles_excluding_card.image_order.includes(:image).map(&:image)
max_images.present? ? images.first(max_images) : images
end
|
#availability ⇒ Object
118
119
120
|
# File 'app/services/feed/google/google_product_presenter.rb', line 118
def availability
product_stock_status.tableize.singularize
end
|
#brand ⇒ Object
110
111
112
|
# File 'app/services/feed/google/google_product_presenter.rb', line 110
def brand
'WarmlyYours'
end
|
#cache_key ⇒ Object
202
203
204
|
# File 'app/services/feed/google/google_product_presenter.rb', line 202
def cache_key
"google_catalog_item_feed/#{r.cache_key}/#{r.item.cache_key}"
end
|
#color_info ⇒ Object
171
172
173
174
175
|
# File 'app/services/feed/google/google_product_presenter.rb', line 171
def color_info
return unless has_variants?
item.spec_output('color') || item.spec_output('finish')
end
|
#condition ⇒ Object
98
99
100
|
# File 'app/services/feed/google/google_product_presenter.rb', line 98
def condition
item_condition
end
|
#dealer_channel_only_product? ⇒ Boolean
28
29
30
|
# File 'app/services/feed/google/google_product_presenter.rb', line 28
def dealer_channel_only_product?
product_catalog_presenter.display_where_to_buy? || product_catalog_presenter.display_dealers?
end
|
#description ⇒ Object
94
95
96
|
# File 'app/services/feed/google/google_product_presenter.rb', line 94
def description
catalog_item.effective_seo_description&.first(5000)
end
|
#google_product_category ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/services/feed/google/google_product_presenter.rb', line 64
def google_product_category
pl_ltree = item_primary_product_line_slug_ltree&.to_s
pc_url = product_category_url
return 499_932 if /power-relay-panels/.match?(pc_url) return 1897 if /thermostats/.match?(pc_url) return 1519 if pc_url =~ /controls/ || pl_ltree&.start_with?('third_party_control_integration') return 2729 if pl_ltree&.start_with?('countertop_heater') && pc_url =~ /heating-elements/ return 499_873 if pl_ltree&.start_with?('floor_heating') return 595 if pl_ltree&.start_with?('mirror') return 2060 if pl_ltree&.start_with?('infrared_heating_panels') return 4544 if pl_ltree&.include?('roof_and_gutter_deicing') return 5362 if pl_ltree&.start_with?('snow_melting') return 586 if pl_ltree&.start_with?('towel_warmer') return 122 if /insulation/.match?(pc_url)
115 end
|
#has_variants? ⇒ Boolean
131
132
133
|
# File 'app/services/feed/google/google_product_presenter.rb', line 131
def has_variants?
variants.present?
end
|
#id ⇒ Object
11
|
# File 'app/services/feed/google/google_product_presenter.rb', line 11
delegate :id, :item, to: :r
|
#image_link ⇒ Object
47
48
49
|
# File 'app/services/feed/google/google_product_presenter.rb', line 47
def image_link
all_images.first&.image_url(encode_format: :webp, width: 1280)
end
|
#item ⇒ Object
11
|
# File 'app/services/feed/google/google_product_presenter.rb', line 11
delegate :id, :item, to: :r
|
#item_group_name ⇒ Object
135
136
137
138
139
|
# File 'app/services/feed/google/google_product_presenter.rb', line 135
def item_group_name
return unless has_variants?
r.item.item_grouping_info&.item_group_name
end
|
#mpn ⇒ Object
114
115
116
|
# File 'app/services/feed/google/google_product_presenter.rb', line 114
def mpn
item_sku
end
|
#output_shipping_dimension(n, unit, precision: 0) ⇒ Object
179
180
181
182
183
184
|
# File 'app/services/feed/google/google_product_presenter.rb', line 179
def output_shipping_dimension(n, unit, precision: 0)
return unless n
sn = ActionController::Base.helpers.number_with_precision n.ceil, precision: precision, strip_insignificant_zeros: true
"#{sn} #{unit}"
end
|
#pickup_method ⇒ Object
123
124
125
|
# File 'app/services/feed/google/google_product_presenter.rb', line 123
def pickup_method
'buy'
end
|
#pickup_sla ⇒ Object
127
128
129
|
# File 'app/services/feed/google/google_product_presenter.rb', line 127
def pickup_sla
'same day'
end
|
#price_with_currency ⇒ Object
102
103
104
|
# File 'app/services/feed/google/google_product_presenter.rb', line 102
def price_with_currency
r.catalog_item.money_price.format(with_currency: true, symbol: false, thousands_separator: '')
end
|
#product_catalog_presenter ⇒ Object
13
14
15
|
# File 'app/services/feed/google/google_product_presenter.rb', line 13
def product_catalog_presenter
@product_catalog_presenter ||= Www::ProductCatalogPresenter.new(view_product_catalog)
end
|
#product_type ⇒ Object
82
83
84
85
86
87
88
|
# File 'app/services/feed/google/google_product_presenter.rb', line 82
def product_type
ar = []
ar << item.product_category.lineage_expanded
ar << item.primary_product_line&.lineage_expanded
ar.compact.join(',')
end
|
#public_specifications ⇒ Object
59
60
61
|
# File 'app/services/feed/google/google_product_presenter.rb', line 59
def public_specifications
product_specifications.reject { |_k, v| v[:visibility] == 'private' }
end
|
#reported_name_for_google ⇒ Object
Alias for Catalog_item#reported_name_for_google
8
|
# File 'app/services/feed/google/google_product_presenter.rb', line 8
delegate :variants, :reported_name_for_google, to: :catalog_item
|
#sale_price_date_range ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'app/services/feed/google/google_product_presenter.rb', line 206
def sale_price_date_range
return nil if sale_price_effective_date.blank?
start_date = sale_price_effective_date.beginning_of_day.iso8601
end_date = if sale_price_expiration_date.present?
sale_price_expiration_date.end_of_day.iso8601
else
Date.current.end_of_month.end_of_day.iso8601
end
"#{start_date}/#{end_date}"
end
|
#sale_price_with_currency ⇒ Object
106
107
108
|
# File 'app/services/feed/google/google_product_presenter.rb', line 106
def sale_price_with_currency
r.catalog_item.money_sale_price.format(with_currency: true, symbol: false, thousands_separator: '')
end
|
#seo_keywords ⇒ Object
32
33
34
|
# File 'app/services/feed/google/google_product_presenter.rb', line 32
def seo_keywords
item.seo_keywords.presence || product_line_page_keywords(item.primary_product_line)
end
|
#shipping_height ⇒ Object
198
199
200
|
# File 'app/services/feed/google/google_product_presenter.rb', line 198
def shipping_height
output_shipping_dimension r.shipping_height_in, 'in'
end
|
#shipping_length ⇒ Object
194
195
196
|
# File 'app/services/feed/google/google_product_presenter.rb', line 194
def shipping_length
output_shipping_dimension r.shipping_length_in, 'in'
end
|
#shipping_weight ⇒ Object
186
187
188
|
# File 'app/services/feed/google/google_product_presenter.rb', line 186
def shipping_weight
output_shipping_dimension r.shipping_weight_lbs, 'lb'
end
|
#shipping_width ⇒ Object
190
191
192
|
# File 'app/services/feed/google/google_product_presenter.rb', line 190
def shipping_width
output_shipping_dimension r.shipping_width_in, 'in'
end
|
#ships_from_country_iso ⇒ Object
220
221
222
|
# File 'app/services/feed/google/google_product_presenter.rb', line 220
def ships_from_country_iso
r.catalog_item.catalog.country&.iso
end
|
#size_info ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/services/feed/google/google_product_presenter.rb', line 141
def size_info
return unless has_variants?
si = spec_output('size').presence
si ||= spec_output('size_overall').presence
si ||= begin
si_tokens = []
use_tokens = facet_tokens.presence
separator = ', '
if use_tokens.nil?
use_tokens = %i[width length]
separator = ' x '
end
use_tokens.select { |t| t.in?(%i[width length]) }.each do |token|
si_tokens << spec_output(token)
rescue StandardError
nil
end
si_tokens = si_tokens.filter_map(&:presence)
si_tokens.presence&.join(separator)
end
si ||= spec_output('coverage').presence
si ||= spec_output('watts').presence
si ||= title.first(100) si
end
|
#spec_output ⇒ Object
Alias for Item#spec_output
177
|
# File 'app/services/feed/google/google_product_presenter.rb', line 177
delegate :spec_output, to: :item
|
#store_code ⇒ Object
36
37
38
39
|
# File 'app/services/feed/google/google_product_presenter.rb', line 36
def store_code
store_item.store.short_name
end
|
#title ⇒ Object
90
91
92
|
# File 'app/services/feed/google/google_product_presenter.rb', line 90
def title
catalog_item.reported_name&.first(150)
end
|
#valid_for_google?(include_image_check: true) ⇒ Boolean
17
18
19
20
21
22
23
24
25
26
|
# File 'app/services/feed/google/google_product_presenter.rb', line 17
def valid_for_google?(include_image_check: true)
url.present? &&
(shipping_weight_lbs&.> 0) &&
(shipping_height_in&.> 0) &&
(shipping_length_in&.> 0) &&
(shipping_width_in&.> 0) &&
!dealer_channel_only_product? &&
(item_condition == 'new') &&
(include_image_check == false || (include_image_check && all_images.present?))
end
|
#variants ⇒ Object
Alias for Catalog_item#variants
8
|
# File 'app/services/feed/google/google_product_presenter.rb', line 8
delegate :variants, :reported_name_for_google, to: :catalog_item
|
#videos ⇒ Object
55
56
57
|
# File 'app/services/feed/google/google_product_presenter.rb', line 55
def videos
Item::VideoRetriever.new(tags: 'for-product-page').process(item).all_videos
end
|