Class: Feed::Openai::OpenaiProductPresenter
- Inherits:
-
Www::ProductCatalogPresenter
- Object
- Www::ProductCatalogPresenter
- Feed::Openai::OpenaiProductPresenter
- Includes:
- Memery
- Defined in:
- app/services/feed/openai/openai_product_presenter.rb
Delegated Instance Attributes collapse
-
#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.
-
#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
- #color ⇒ Object
- #condition ⇒ Object
- #currency ⇒ Object
- #dealer_channel_only_product? ⇒ Boolean
- #delivery_estimate ⇒ Object
- #description ⇒ Object
- #dimensions ⇒ Object
- #enable_checkout ⇒ Object
- #enable_search ⇒ Object
- #gender ⇒ Object
- #geo_availability ⇒ Object
- #geo_price ⇒ Object
- #gtin ⇒ Object
- #has_variants? ⇒ Boolean
- #height ⇒ Object
- #image_link ⇒ Object
- #item_group_id ⇒ Object
- #item_group_title ⇒ Object
- #length ⇒ Object
- #link ⇒ Object
- #material ⇒ Object
- #mpn ⇒ Object
- #offer_id ⇒ Object
-
#openai_id ⇒ Object
OpenAI Product Feed Fields.
- #popularity_score ⇒ Object
- #price ⇒ Object
- #product_catalog_presenter ⇒ Object
- #product_category ⇒ Object
- #product_review_count ⇒ Object
- #product_review_rating ⇒ Object
- #public_specifications ⇒ Object
- #q_and_a ⇒ Object
- #related_product_id ⇒ Object
- #relationship_type ⇒ Object
- #return_policy ⇒ Object
- #return_rate ⇒ Object
- #return_window ⇒ Object
- #seller_name ⇒ Object
- #seller_privacy_policy ⇒ Object
- #seller_tos ⇒ Object
- #seller_url ⇒ Object
- #shipping ⇒ Object
- #size ⇒ Object
- #size_system ⇒ Object
- #store_review_count ⇒ Object
- #store_review_rating ⇒ Object
- #title ⇒ Object
- #valid_for_openai? ⇒ Boolean
- #weight ⇒ Object
- #width ⇒ Object
Instance Method Details
#additional_image_links ⇒ Object
43 44 45 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 43 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
33 34 35 36 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 33 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
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 135 def availability case product_stock_status.downcase when 'instock' 'in_stock' when 'outofstock' 'out_of_stock' when 'preorder' 'preorder' else 'in_stock' end end |
#brand ⇒ Object
88 89 90 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 88 def brand 'WarmlyYours' end |
#color ⇒ Object
168 169 170 171 172 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 168 def color return nil unless has_variants? item.spec_output('color') || item.spec_output('finish') end |
#condition ⇒ Object
76 77 78 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 76 def condition item_condition end |
#currency ⇒ Object
131 132 133 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 131 def currency r.catalog_item.money_price.currency.iso_code end |
#dealer_channel_only_product? ⇒ Boolean
29 30 31 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 29 def dealer_channel_only_product? product_catalog_presenter.display_where_to_buy? || product_catalog_presenter.display_dealers? end |
#delivery_estimate ⇒ Object
198 199 200 201 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 198 def delivery_estimate # Estimate 3-5 business days for standard shipping (Date.current + 4.days).iso8601 end |
#description ⇒ Object
68 69 70 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 68 def description catalog_item.effective_seo_description&.first(5000) end |
#dimensions ⇒ Object
97 98 99 100 101 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 97 def dimensions return nil unless shipping_length_in && shipping_width_in && shipping_height_in "#{shipping_length_in.to_i}x#{shipping_width_in.to_i}x#{shipping_height_in.to_i} in" end |
#enable_checkout ⇒ Object
152 153 154 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 152 def enable_checkout true end |
#enable_search ⇒ Object
148 149 150 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 148 def enable_search true end |
#gender ⇒ Object
184 185 186 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 184 def gender 'unisex' end |
#geo_availability ⇒ Object
285 286 287 288 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 285 def geo_availability # Placeholder - could be based on actual geo-specific availability nil end |
#geo_price ⇒ Object
280 281 282 283 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 280 def geo_price # Placeholder - could be based on actual geo-specific pricing nil end |
#gtin ⇒ Object
56 57 58 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 56 def gtin item.upc end |
#has_variants? ⇒ Boolean
15 16 17 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 15 def has_variants? variants.present? end |
#height ⇒ Object
115 116 117 118 119 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 115 def height return nil unless shipping_height_in "#{shipping_height_in.to_i}in" end |
#id ⇒ Object
Alias for R#id
9 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 9 delegate :id, :item, to: :r |
#image_link ⇒ Object
39 40 41 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 39 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/openai/openai_product_presenter.rb', line 9 delegate :id, :item, to: :r |
#item_group_id ⇒ Object
156 157 158 159 160 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 156 def item_group_id return nil unless has_variants? r.item.item_grouping_info&.item_group_name || "GROUP_#{item.id}" end |
#item_group_title ⇒ Object
162 163 164 165 166 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 162 def item_group_title return nil unless has_variants? r.item.item_grouping_info&.item_group_name end |
#length ⇒ Object
103 104 105 106 107 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 103 def length return nil unless shipping_length_in "#{shipping_length_in.to_i}in" end |
#link ⇒ Object
72 73 74 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 72 def link url end |
#material ⇒ Object
92 93 94 95 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 92 def material # Extract material from specifications or use default spec_output('material') || spec_output('finish') || 'Metal' end |
#mpn ⇒ Object
60 61 62 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 60 def mpn item_sku end |
#offer_id ⇒ Object
188 189 190 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 188 def offer_id "#{item_sku}-#{price}-#{currency}" end |
#openai_id ⇒ Object
OpenAI Product Feed Fields
52 53 54 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 52 def openai_id item_sku end |
#popularity_score ⇒ Object
227 228 229 230 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 227 def popularity_score # Placeholder - could be based on actual sales data 4.5 end |
#price ⇒ Object
127 128 129 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 127 def price r.catalog_item.money_price.cents / 100.0 end |
#product_catalog_presenter ⇒ Object
11 12 13 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 11 def product_catalog_presenter @product_catalog_presenter ||= Www::ProductCatalogPresenter.new(view_product_catalog) end |
#product_category ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 80 def product_category # Convert our category structure to OpenAI format ar = [] ar << item.product_category. ar << item.primary_product_line&. ar.compact.join(' > ') end |
#product_review_count ⇒ Object
237 238 239 240 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 237 def product_review_count # Placeholder - could be based on actual review data 0 end |
#product_review_rating ⇒ Object
242 243 244 245 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 242 def # Placeholder - could be based on actual review data 0.0 end |
#public_specifications ⇒ Object
47 48 49 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 47 def public_specifications product_specifications.select { |k, v| v[:visibility] != 'private' } end |
#q_and_a ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 257 def q_and_a # Generate basic Q&A based on product characteristics questions = [] questions << 'Q: Is this a new product? A: Yes, this is a brand new item.' if item_condition == 'new' questions << "Q: What is the shipping weight? A: This item weighs approximately #{shipping_weight_lbs.to_i} pounds." if shipping_weight_lbs&.> 0 questions << "Q: What material is this made of? A: This product is made of #{material}." if material.present? questions.any? ? questions.join(' ') : nil end |
#related_product_id ⇒ Object
270 271 272 273 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 270 def # Placeholder - could be based on actual related products nil end |
#relationship_type ⇒ Object
275 276 277 278 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 275 def relationship_type # Placeholder - could be based on actual product relationships nil end |
#reported_name_for_google ⇒ Object
Alias for Catalog_item#reported_name_for_google
6 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 6 delegate :variants, :reported_name_for_google, to: :catalog_item |
#return_policy ⇒ Object
219 220 221 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 219 def return_policy "https://www.warmlyyours.com/#{catalog_item.catalog.locale_for_catalog}/company/return-policy" end |
#return_rate ⇒ Object
232 233 234 235 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 232 def return_rate # Placeholder - could be based on actual return data 1.0 end |
#return_window ⇒ Object
223 224 225 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 223 def return_window 365 end |
#seller_name ⇒ Object
203 204 205 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 203 def seller_name 'WarmlyYours' end |
#seller_privacy_policy ⇒ Object
211 212 213 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 211 def seller_privacy_policy "https://www.warmlyyours.com/#{catalog_item.catalog.locale_for_catalog}/company/privacy-policy" end |
#seller_tos ⇒ Object
215 216 217 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 215 def seller_tos "https://www.warmlyyours.com/#{catalog_item.catalog.locale_for_catalog}/company/terms-of-use" end |
#seller_url ⇒ Object
207 208 209 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 207 def seller_url "https://www.warmlyyours.com/#{catalog_item.catalog.locale_for_catalog}" end |
#shipping ⇒ Object
192 193 194 195 196 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 192 def shipping # Basic shipping info - can be enhanced with actual shipping data country_iso = catalog_item.catalog.country&.iso || 'US' "#{country_iso}::Standard:0.00 #{currency}" end |
#size ⇒ Object
174 175 176 177 178 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 174 def size return nil unless has_variants? size_info end |
#size_system ⇒ Object
180 181 182 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 180 def size_system 'US' end |
#store_review_count ⇒ Object
247 248 249 250 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 247 def store_review_count # Placeholder - could be based on actual store review data 0 end |
#store_review_rating ⇒ Object
252 253 254 255 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 252 def # Placeholder - could be based on actual store review data 0.0 end |
#title ⇒ Object
64 65 66 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 64 def title catalog_item.reported_name&.first(150) end |
#valid_for_openai? ⇒ Boolean
19 20 21 22 23 24 25 26 27 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 19 def valid_for_openai? (shipping_weight_lbs&.> 0) && (shipping_height_in&.> 0) && (shipping_length_in&.> 0) && (shipping_width_in&.> 0) && !dealer_channel_only_product? && (item_condition == 'new') && all_images.present? end |
#variants ⇒ Object
Alias for Catalog_item#variants
6 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 6 delegate :variants, :reported_name_for_google, to: :catalog_item |
#weight ⇒ Object
121 122 123 124 125 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 121 def weight return nil unless shipping_weight_lbs "#{shipping_weight_lbs.to_i}lb" end |
#width ⇒ Object
109 110 111 112 113 |
# File 'app/services/feed/openai/openai_product_presenter.rb', line 109 def width return nil unless shipping_width_in "#{shipping_width_in.to_i}in" end |