Class: Feed::Openai::OpenaiProductPresenter

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

Delegated Instance Attributes collapse

Instance Method Summary collapse

Instance Method Details



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

#availabilityObject



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

#brandObject



88
89
90
# File 'app/services/feed/openai/openai_product_presenter.rb', line 88

def brand
  'WarmlyYours'
end

#colorObject



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

#conditionObject



76
77
78
# File 'app/services/feed/openai/openai_product_presenter.rb', line 76

def condition
  item_condition
end

#currencyObject



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

Returns:

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



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

#descriptionObject



68
69
70
# File 'app/services/feed/openai/openai_product_presenter.rb', line 68

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

#dimensionsObject



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_checkoutObject



152
153
154
# File 'app/services/feed/openai/openai_product_presenter.rb', line 152

def enable_checkout
  true
end

#enable_searchObject



148
149
150
# File 'app/services/feed/openai/openai_product_presenter.rb', line 148

def enable_search
  true
end

#genderObject



184
185
186
# File 'app/services/feed/openai/openai_product_presenter.rb', line 184

def gender
  'unisex'
end

#geo_availabilityObject



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_priceObject



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

#gtinObject



56
57
58
# File 'app/services/feed/openai/openai_product_presenter.rb', line 56

def gtin
  item.upc
end

#has_variants?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/services/feed/openai/openai_product_presenter.rb', line 15

def has_variants?
  variants.present?
end

#heightObject



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

#idObject

Alias for R#id

Returns:

  • (Object)

    R#id

See Also:



9
# File 'app/services/feed/openai/openai_product_presenter.rb', line 9

delegate :id, :item, to: :r


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

#itemObject

Alias for R#item

Returns:

  • (Object)

    R#item

See Also:



9
# File 'app/services/feed/openai/openai_product_presenter.rb', line 9

delegate :id, :item, to: :r

#item_group_idObject



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_titleObject



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

#lengthObject



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


72
73
74
# File 'app/services/feed/openai/openai_product_presenter.rb', line 72

def link
  url
end

#materialObject



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

#mpnObject



60
61
62
# File 'app/services/feed/openai/openai_product_presenter.rb', line 60

def mpn
  item_sku
end

#offer_idObject



188
189
190
# File 'app/services/feed/openai/openai_product_presenter.rb', line 188

def offer_id
  "#{item_sku}-#{price}-#{currency}"
end

#openai_idObject

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_scoreObject



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

#priceObject



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_presenterObject



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_categoryObject



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.lineage_expanded
  ar << item.primary_product_line&.lineage_expanded
  ar.compact.join(' > ')
end

#product_review_countObject



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_ratingObject



242
243
244
245
# File 'app/services/feed/openai/openai_product_presenter.rb', line 242

def product_review_rating
  # Placeholder - could be based on actual review data
  0.0
end

#public_specificationsObject



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_aObject



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


270
271
272
273
# File 'app/services/feed/openai/openai_product_presenter.rb', line 270

def related_product_id
  # Placeholder - could be based on actual related products
  nil
end

#relationship_typeObject



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_googleObject

Alias for Catalog_item#reported_name_for_google

Returns:

  • (Object)

    Catalog_item#reported_name_for_google

See Also:



6
# File 'app/services/feed/openai/openai_product_presenter.rb', line 6

delegate :variants, :reported_name_for_google, to: :catalog_item

#return_policyObject



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_rateObject



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_windowObject



223
224
225
# File 'app/services/feed/openai/openai_product_presenter.rb', line 223

def return_window
  365
end

#seller_nameObject



203
204
205
# File 'app/services/feed/openai/openai_product_presenter.rb', line 203

def seller_name
  'WarmlyYours'
end

#seller_privacy_policyObject



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_tosObject



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_urlObject



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

#shippingObject



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

#sizeObject



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_systemObject



180
181
182
# File 'app/services/feed/openai/openai_product_presenter.rb', line 180

def size_system
  'US'
end

#store_review_countObject



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_ratingObject



252
253
254
255
# File 'app/services/feed/openai/openai_product_presenter.rb', line 252

def store_review_rating
  # Placeholder - could be based on actual store review data
  0.0
end

#titleObject



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

Returns:

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

#variantsObject

Alias for Catalog_item#variants

Returns:

  • (Object)

    Catalog_item#variants

See Also:



6
# File 'app/services/feed/openai/openai_product_presenter.rb', line 6

delegate :variants, :reported_name_for_google, to: :catalog_item

#weightObject



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

#widthObject



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