Module: Models::CatalogItemWayfairHelper
- Extended by:
- ActiveSupport::Concern
- Included in:
- CatalogItem
- Defined in:
- app/concerns/models/catalog_item_wayfair_helper.rb
Overview
Provides typed accessors for Wayfair catalog item data stored in retailer_information
Uses jsonb_accessor gem for type-safe access to nested JSON fields
Data structure in retailer_information:
{
product_id: Integer, # Wayfair's internal product ID
status: String, # Product status (e.g., 'LIVE')
display_sku: String, # Customer-facing SKU (e.g., 'W001498355')
internal_sku: String, # Wayfair's internal variant SKU
retail_price: Decimal, # Current retail price on Wayfair
primary_image_url: String, # URL to primary product image
synced_at: DateTime, # Last sync timestamp
taxonomy_category_id: Integer, # Wayfair taxonomy category ID (e.g., 997)
class_name: String, # Wayfair product class name (e.g., 'Space Heaters')
class_id: Integer, # Wayfair class ID (same as taxonomy_category_id usually)
upc: String, # UPC barcode
product_urls: Array # Array of product page URLs
}
Class Method Summary collapse
-
.wayfairs ⇒ ActiveRecord::Relation<Models::CatalogItemWayfairHelper>
A relation of Models::CatalogItemWayfairHelpers that are wayfairs.
Instance Method Summary collapse
-
#wayfair_catalog_item? ⇒ Boolean
Check if this catalog item belongs to a Wayfair catalog.
-
#wayfair_primary_product_url ⇒ Object
Get the first product URL from the array (typically US).
-
#wayfair_product_url ⇒ Object
Wayfair product URL (if display_sku is available) Format: https://www.wayfair.com/pd/product/W001498355.html.
-
#wayfair_pull_taxonomy_schema(orchestrator = nil) ⇒ WayfairSchema?
Pull taxonomy schema for this item's category.
-
#wayfair_sync_age ⇒ Object
Age of the last sync in human-readable format.
-
#wayfair_synced? ⇒ Boolean
Check if Wayfair data has been synced.
-
#wayfair_taxonomy_available? ⇒ Boolean
Check if taxonomy category is set (required for attribute updates).
-
#wayfair_taxonomy_category_id_in_effect ⇒ Object
The effective taxonomy category ID for this item Used to look up WayfairSchema for attribute definitions.
Class Method Details
.wayfairs ⇒ ActiveRecord::Relation<Models::CatalogItemWayfairHelper>
A relation of Models::CatalogItemWayfairHelpers that are wayfairs. Active Record Scope
26 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 26 scope :wayfairs, -> { where(catalog_id: CatalogConstants::WAYFAIR_CATALOGS) } |
Instance Method Details
#wayfair_catalog_item? ⇒ Boolean
Check if this catalog item belongs to a Wayfair catalog
52 53 54 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 52 def wayfair_catalog_item? CatalogConstants::WAYFAIR_CATALOGS.include?(catalog_id) end |
#wayfair_primary_product_url ⇒ Object
Get the first product URL from the array (typically US)
81 82 83 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 81 def wayfair_primary_product_url wayfair_product_urls&.first end |
#wayfair_product_url ⇒ Object
Wayfair product URL (if display_sku is available)
Format: https://www.wayfair.com/pd/product/W001498355.html
74 75 76 77 78 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 74 def wayfair_product_url return nil unless wayfair_display_sku.present? "https://www.wayfair.com/pd/product/#{wayfair_display_sku}.html" end |
#wayfair_pull_taxonomy_schema(orchestrator = nil) ⇒ WayfairSchema?
Pull taxonomy schema for this item's category
95 96 97 98 99 100 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 95 def wayfair_pull_taxonomy_schema(orchestrator = nil) return nil unless wayfair_taxonomy_category_id_in_effect orchestrator ||= Edi::Wayfair::Orchestrator.build(:wayfair_us) orchestrator.pull_taxonomy_schema(wayfair_taxonomy_category_id_in_effect) end |
#wayfair_sync_age ⇒ Object
Age of the last sync in human-readable format
86 87 88 89 90 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 86 def wayfair_sync_age return nil unless wayfair_synced_at ActionController::Base.helpers.time_ago_in_words(wayfair_synced_at) end |
#wayfair_synced? ⇒ Boolean
Check if Wayfair data has been synced
57 58 59 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 57 def wayfair_synced? wayfair_synced_at.present? end |
#wayfair_taxonomy_available? ⇒ Boolean
Check if taxonomy category is set (required for attribute updates)
62 63 64 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 62 def wayfair_taxonomy_available? wayfair_taxonomy_category_id.present? end |
#wayfair_taxonomy_category_id_in_effect ⇒ Object
The effective taxonomy category ID for this item
Used to look up WayfairSchema for attribute definitions
68 69 70 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 68 def wayfair_taxonomy_category_id_in_effect wayfair_taxonomy_category_id || wayfair_class_id end |