Class: Feed::Google::GoogleProductPresenter

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

Delegated Instance Attributes collapse

Instance Method Summary collapse

Instance Method Details



49
50
51
# File 'app/services/feed/google/google_product_presenter.rb', line 49

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



39
40
41
42
# File 'app/services/feed/google/google_product_presenter.rb', line 39

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



116
117
118
# File 'app/services/feed/google/google_product_presenter.rb', line 116

def availability
  product_stock_status.tableize.singularize
end

#brandObject



108
109
110
# File 'app/services/feed/google/google_product_presenter.rb', line 108

def brand
  'WarmlyYours'
end

#cache_keyObject



204
205
206
# File 'app/services/feed/google/google_product_presenter.rb', line 204

def cache_key
  "google_catalog_item_feed/#{r.cache_key}/#{r.item.cache_key}"
end

#color_infoObject



173
174
175
176
177
# File 'app/services/feed/google/google_product_presenter.rb', line 173

def color_info
  return unless has_variants?

  item.spec_output('color') || item.spec_output('finish')
end

#conditionObject



96
97
98
# File 'app/services/feed/google/google_product_presenter.rb', line 96

def condition
  item_condition
end

#dealer_channel_only_product?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/services/feed/google/google_product_presenter.rb', line 26

def dealer_channel_only_product?
  product_catalog_presenter.display_where_to_buy? || product_catalog_presenter.display_dealers?
end

#descriptionObject



92
93
94
# File 'app/services/feed/google/google_product_presenter.rb', line 92

def description
  catalog_item.effective_seo_description&.first(5000)
end

#google_product_categoryObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/services/feed/google/google_product_presenter.rb', line 62

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?('radiant_panel') # | 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?Object

Alias for Catalog_item#has_variants?

Returns:

  • (Object)

    Catalog_item#has_variants?

See Also:



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

delegate :variants, :has_variants?, :reported_name_for_google, to: :catalog_item

#idObject

Alias for R#id

Returns:

  • (Object)

    R#id

See Also:



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

delegate :id, :item, to: :r


45
46
47
# File 'app/services/feed/google/google_product_presenter.rb', line 45

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:



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

delegate :id, :item, to: :r

#item_group_nameObject



133
134
135
136
137
# File 'app/services/feed/google/google_product_presenter.rb', line 133

def item_group_name
  return unless has_variants?

  r.item.item_grouping_info&.item_group_name
end

#mpnObject



112
113
114
# File 'app/services/feed/google/google_product_presenter.rb', line 112

def mpn
  item_sku
end

#output_shipping_dimension(n, unit, precision: 0) ⇒ Object



181
182
183
184
185
186
# File 'app/services/feed/google/google_product_presenter.rb', line 181

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



125
126
127
# File 'app/services/feed/google/google_product_presenter.rb', line 125

def pickup_sla
  'same day'
end

#price_with_currencyObject



100
101
102
# File 'app/services/feed/google/google_product_presenter.rb', line 100

def price_with_currency
  r.catalog_item.money_price.format(with_currency: true, symbol: false, thousands_separator: '')
end

#product_catalog_presenterObject



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

def product_catalog_presenter
  @product_catalog_presenter ||= Www::ProductCatalogPresenter.new(view_product_catalog)
end

#product_typeObject



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

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



57
58
59
# File 'app/services/feed/google/google_product_presenter.rb', line 57

def public_specifications
  product_specifications.select { |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:



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

delegate :variants, :has_variants?, :reported_name_for_google, to: :catalog_item

#sale_price_date_rangeObject



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'app/services/feed/google/google_product_presenter.rb', line 208

def sale_price_date_range
  return nil unless sale_price_effective_date.present?

  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



104
105
106
# File 'app/services/feed/google/google_product_presenter.rb', line 104

def sale_price_with_currency
  r.catalog_item.money_sale_price.format(with_currency: true, symbol: false, thousands_separator: '')
end

#seo_keywordsObject



30
31
32
# File 'app/services/feed/google/google_product_presenter.rb', line 30

def seo_keywords
  item.seo_keywords.presence || product_line_page_keywords(item.primary_product_line)
end

#shipping_heightObject



200
201
202
# File 'app/services/feed/google/google_product_presenter.rb', line 200

def shipping_height
  output_shipping_dimension r.shipping_height_in, 'in'
end

#shipping_lengthObject



196
197
198
# File 'app/services/feed/google/google_product_presenter.rb', line 196

def shipping_length
  output_shipping_dimension r.shipping_length_in, 'in'
end

#shipping_weightObject



188
189
190
# File 'app/services/feed/google/google_product_presenter.rb', line 188

def shipping_weight
  output_shipping_dimension r.shipping_weight_lbs, 'lb'
end

#shipping_widthObject



192
193
194
# File 'app/services/feed/google/google_product_presenter.rb', line 192

def shipping_width
  output_shipping_dimension r.shipping_width_in, 'in'
end

#ships_from_country_isoObject



222
223
224
# File 'app/services/feed/google/google_product_presenter.rb', line 222

def ships_from_country_iso
  r.catalog_item.catalog.country&.iso
end

#size_infoObject



139
140
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
170
171
# File 'app/services/feed/google/google_product_presenter.rb', line 139

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.map(&:presence).compact
    if si_tokens.present?
      si_tokens.join(separator)
    else
      nil
    end
  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:



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

delegate :spec_output, to: :item

#store_codeObject



34
35
36
37
# File 'app/services/feed/google/google_product_presenter.rb', line 34

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

#titleObject



88
89
90
# File 'app/services/feed/google/google_product_presenter.rb', line 88

def title
  catalog_item.reported_name&.first(150)
end

#valid_for_google?(include_image_check: true) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
# File 'app/services/feed/google/google_product_presenter.rb', line 15

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:



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

delegate :variants, :has_variants?, :reported_name_for_google, to: :catalog_item

#videosObject



53
54
55
# File 'app/services/feed/google/google_product_presenter.rb', line 53

def videos
  Item::VideoRetriever.new(tags: 'for-product-page').process(item).all_videos
end