Class: Feed::Google::GoogleProductPresenter
- Inherits:
-
Www::ProductCatalogPresenter
- Object
- Www::ProductCatalogPresenter
- Feed::Google::GoogleProductPresenter
- Includes:
- Memery
- Defined in:
- app/services/feed/google/google_product_presenter.rb
Delegated Instance Attributes collapse
-
#has_variants? ⇒ Object
Alias for Catalog_item#has_variants?.
-
#id ⇒ Object
Alias for R#id.
-
#item ⇒ Object
Alias for R#item.
-
#reported_name_for_google ⇒ Object
Alias for Catalog_item#reported_name_for_google.
-
#spec_output ⇒ Object
Alias for Item#spec_output.
-
#variants ⇒ Object
Alias for Catalog_item#variants.
Instance Method Summary collapse
- #additional_image_links ⇒ Object
- #all_images(max_images: nil) ⇒ Object
- #availability ⇒ Object
- #brand ⇒ Object
- #cache_key ⇒ Object
- #color_info ⇒ Object
- #condition ⇒ Object
- #dealer_channel_only_product? ⇒ Boolean
- #description ⇒ Object
- #google_product_category ⇒ Object
- #image_link ⇒ Object
- #item_group_name ⇒ Object
- #mpn ⇒ Object
- #output_shipping_dimension(n, unit, precision: 0) ⇒ Object
- #pickup_method ⇒ Object
- #pickup_sla ⇒ Object
- #price_with_currency ⇒ Object
- #product_catalog_presenter ⇒ Object
- #product_type ⇒ Object
- #public_specifications ⇒ Object
- #sale_price_date_range ⇒ Object
- #sale_price_with_currency ⇒ Object
- #seo_keywords ⇒ Object
- #shipping_height ⇒ Object
- #shipping_length ⇒ Object
- #shipping_weight ⇒ Object
- #shipping_width ⇒ Object
- #ships_from_country_iso ⇒ Object
- #size_info ⇒ Object
- #store_code ⇒ Object
- #title ⇒ Object
- #valid_for_google?(include_image_check: true) ⇒ Boolean
- #videos ⇒ Object
Instance Method Details
#additional_image_links ⇒ Object
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 |
#availability ⇒ Object
116 117 118 |
# File 'app/services/feed/google/google_product_presenter.rb', line 116 def availability product_stock_status.tableize.singularize end |
#brand ⇒ Object
108 109 110 |
# File 'app/services/feed/google/google_product_presenter.rb', line 108 def brand 'WarmlyYours' end |
#cache_key ⇒ Object
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_info ⇒ Object
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 |
#condition ⇒ Object
96 97 98 |
# File 'app/services/feed/google/google_product_presenter.rb', line 96 def condition item_condition end |
#dealer_channel_only_product? ⇒ 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 |
#description ⇒ Object
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_category ⇒ Object
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?
6 |
# File 'app/services/feed/google/google_product_presenter.rb', line 6 delegate :variants, :has_variants?, :reported_name_for_google, to: :catalog_item |
#id ⇒ Object
Alias for R#id
9 |
# File 'app/services/feed/google/google_product_presenter.rb', line 9 delegate :id, :item, to: :r |
#image_link ⇒ Object
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 |
#item ⇒ Object
Alias for R#item
9 |
# File 'app/services/feed/google/google_product_presenter.rb', line 9 delegate :id, :item, to: :r |
#item_group_name ⇒ Object
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 |
#mpn ⇒ Object
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_method ⇒ Object
121 122 123 |
# File 'app/services/feed/google/google_product_presenter.rb', line 121 def pickup_method 'buy' end |
#pickup_sla ⇒ Object
125 126 127 |
# File 'app/services/feed/google/google_product_presenter.rb', line 125 def pickup_sla 'same day' end |
#price_with_currency ⇒ Object
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_presenter ⇒ Object
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_type ⇒ Object
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. ar << item.primary_product_line&. ar.compact.join(',') end |
#public_specifications ⇒ Object
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_google ⇒ Object
Alias for Catalog_item#reported_name_for_google
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_range ⇒ Object
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_currency ⇒ Object
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_keywords ⇒ Object
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_height ⇒ Object
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_length ⇒ Object
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_weight ⇒ Object
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_width ⇒ Object
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_iso ⇒ Object
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_info ⇒ Object
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_output ⇒ Object
Alias for Item#spec_output
179 |
# File 'app/services/feed/google/google_product_presenter.rb', line 179 delegate :spec_output, to: :item |
#store_code ⇒ Object
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 |
#title ⇒ Object
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
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 |
#variants ⇒ Object
Alias for Catalog_item#variants
6 |
# File 'app/services/feed/google/google_product_presenter.rb', line 6 delegate :variants, :has_variants?, :reported_name_for_google, to: :catalog_item |
#videos ⇒ Object
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 |