Class: Oembed::ProductProvider
- Inherits:
-
Object
- Object
- Oembed::ProductProvider
- Defined in:
- app/services/oembed/product_provider.rb
Defined Under Namespace
Classes: ProductNotFoundError, ProductUnavailableError
Instance Method Summary collapse
-
#get(options = {}) ⇒ Hash
Get rendered product HTML.
-
#render_for_locale(sku, locale = 'en-US', include_schema: true) ⇒ String?
Render product embed HTML for the frontend (blog display) This is called during content refresh and normal rendering Handles locale-aware pricing and availability checks.
Instance Method Details
#get(options = {}) ⇒ Hash
Get rendered product HTML
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/oembed/product_provider.rb', line 37 def get( = {}) sku = [:sku].to_s.strip locale = [:locale].to_s.presence || 'en-US' = [:embedded_asset_uuid].presence raise ProductNotFoundError, 'No SKU provided' if sku.blank? # Try exact match first, then case-insensitive item = Item.find_by(sku: sku) || Item.where('UPPER(sku) = ?', sku.upcase).first raise ProductNotFoundError, "Product not found: #{sku}" if item.nil? # For CRM editor preview, show the product with locale-aware pricing # The frontend rendering will handle final availability checks build_response(item, sku, locale, embedded_asset_uuid: ) end |
#render_for_locale(sku, locale = 'en-US', include_schema: true) ⇒ String?
Render product embed HTML for the frontend (blog display)
This is called during content refresh and normal rendering
Handles locale-aware pricing and availability checks
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/services/oembed/product_provider.rb', line 61 def render_for_locale(sku, locale = 'en-US', include_schema: true) sku_stripped = sku.to_s.strip item = Item.find_by(sku: sku_stripped) || Item.where('UPPER(sku) = ?', sku_stripped.upcase).first return nil if item.nil? catalog_id = catalog_id_for_locale(locale) catalog_item = item.catalog_items.find_by(catalog_id: catalog_id) # Check availability - return nil if product shouldn't be displayed return nil unless product_available?(item, catalog_item) # Render the product card card_html = render_product_card(item, catalog_item, locale) return nil if card_html.nil? # Optionally include JSON-LD schema for SEO if include_schema schema_html = render_product_schema(item, catalog_item, locale) "#{card_html}#{schema_html}" else card_html end end |