Class: Feed::Google::GoogleProductPresenter

Inherits:
Www::ProductCatalogPresenter
  • Object
show all
Includes:
Memery
Defined in:
app/services/feed/google/google_product_presenter.rb

Overview

Service object: google product presenter.

Direct Known Subclasses

OpenaiAds::ProductPresenter

Delegated Instance Attributes collapse

Instance Method Summary collapse

Instance Method Details



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

#availabilityObject



118
119
120
# File 'app/services/feed/google/google_product_presenter.rb', line 118

def availability
  product_stock_status.tableize.singularize
end

#brandObject



110
111
112
# File 'app/services/feed/google/google_product_presenter.rb', line 110

def brand
  'WarmlyYours'
end

#cache_keyObject



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_infoObject



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

#conditionObject



98
99
100
# File 'app/services/feed/google/google_product_presenter.rb', line 98

def condition
  item_condition
end

#dealer_channel_only_product?Boolean

Returns:

  • (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

#descriptionObject



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_categoryObject



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) # Hardware > Power & Electrical Supplies > Electrical Switches > Specialty Electrical Switches & Relays
  return 1897   if /thermostats/.match?(pc_url) # Hardware  | Heating, Ventilation & Air Conditioning  | HVAC Controls  | Thermostats
  return 1519   if pc_url =~ /controls/ || pl_ltree&.start_with?('third_party_control_integration') # Hardware  | Heating, Ventilation & Air Conditioning  | HVAC Controls
  return 2729   if pl_ltree&.start_with?('countertop_heater') && pc_url =~ /heating-elements/ # Hardware	Building Materials	Countertops
  return 499_873 if pl_ltree&.start_with?('floor_heating') # | Hardware  | Heating, Ventilation & Air Conditioning
  return 595    if pl_ltree&.start_with?('mirror') # Home & Garden	Decor	Mirrors
  return 2060   if pl_ltree&.start_with?('infrared_heating_panels') # | Home & Garden  | Household Appliances  | Climate Control Appliances  | Heating Radiators
  return 4544   if pl_ltree&.include?('roof_and_gutter_deicing') # Hardware	Building Materials	Roofing	Gutter Accessories
  return 5362   if pl_ltree&.start_with?('snow_melting') #	Home & Garden	Lawn & Garden	Snow Removal
  return 586    if pl_ltree&.start_with?('towel_warmer') # | Home & Garden  | Bathroom Accessories  | Towel Racks & Holders
  return 122 if /insulation/.match?(pc_url) #  Hardware	Building Materials	Insulation

  115 #	Hardware > Building Materials
end

#has_variants?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'app/services/feed/google/google_product_presenter.rb', line 131

def has_variants?
  variants.present?
end

#idObject

Alias for R#id

Returns:

  • (Object)

    R#id

See Also:



11
# File 'app/services/feed/google/google_product_presenter.rb', line 11

delegate :id, :item, to: :r


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

#itemObject

Alias for R#item

Returns:

  • (Object)

    R#item

See Also:



11
# File 'app/services/feed/google/google_product_presenter.rb', line 11

delegate :id, :item, to: :r

#item_group_nameObject



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

#mpnObject



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_slaObject



127
128
129
# File 'app/services/feed/google/google_product_presenter.rb', line 127

def pickup_sla
  'same day'
end

#price_with_currencyObject



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_presenterObject



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_typeObject



82
83
84
85
86
87
88
# File 'app/services/feed/google/google_product_presenter.rb', line 82

def product_type
  # Feed::ProductTypeGenerator.process(item: item, separator: ' > ')
  ar = []
  ar << item.product_category.lineage_expanded
  ar << item.primary_product_line&.lineage_expanded
  ar.compact.join(',')
end

#public_specificationsObject



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_googleObject

Alias for Catalog_item#reported_name_for_google

Returns:

  • (Object)

    Catalog_item#reported_name_for_google

See Also:



8
# File 'app/services/feed/google/google_product_presenter.rb', line 8

delegate :variants, :reported_name_for_google, to: :catalog_item

#sale_price_date_rangeObject



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
               # Default to end of current month if no expiration date
               Date.current.end_of_month.end_of_day.iso8601
             end

  "#{start_date}/#{end_date}"
end

#sale_price_with_currencyObject



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_keywordsObject



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_heightObject



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_lengthObject



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_weightObject



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_widthObject



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_isoObject



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_infoObject



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?

  # Combination of our facets for google
  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
    # We can only use token related to size
    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) # Worst possible size info
  si
end

#spec_outputObject

Alias for Item#spec_output

Returns:

  • (Object)

    Item#spec_output

See Also:



177
# File 'app/services/feed/google/google_product_presenter.rb', line 177

delegate :spec_output, to: :item

#store_codeObject



36
37
38
39
# File 'app/services/feed/google/google_product_presenter.rb', line 36

def store_code
  # This has to match what's in My Google BUsiness Advanced options
  store_item.store.short_name
end

#titleObject



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

Returns:

  • (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

#variantsObject

Alias for Catalog_item#variants

Returns:

  • (Object)

    Catalog_item#variants

See Also:



8
# File 'app/services/feed/google/google_product_presenter.rb', line 8

delegate :variants, :reported_name_for_google, to: :catalog_item

#videosObject



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