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 # URLs from the current product record
parent_product_codes: Array # Complete WRM parent set from a full scan
parent_product_codes_candidate: Array # Reduced set awaiting confirmation
}
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_class_diverged? ⇒ Boolean
True when we've set a desired class that differs from the class Wayfair currently reports for the item (i.e. a re-class is pending).
-
#wayfair_effective_taxonomy_category_id ⇒ Integer?
The taxonomy category we intend this item to carry — the desired override when set, else the current synced category.
-
#wayfair_primary_product_url ⇒ String?
Get the first product URL from the array (typically US).
-
#wayfair_product_url ⇒ String?
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 ⇒ String?
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 ⇒ Integer?
The current (synced) taxonomy category ID for this item — what Wayfair has it classified as.
Class Method Details
.wayfairs ⇒ ActiveRecord::Relation<Models::CatalogItemWayfairHelper>
A relation of Models::CatalogItemWayfairHelpers that are wayfairs. Active Record Scope
28 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 28 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
101 102 103 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 101 def wayfair_catalog_item? CatalogConstants::WAYFAIR_CATALOGS.include?(catalog_id) end |
#wayfair_class_diverged? ⇒ Boolean
True when we've set a desired class that differs from the class Wayfair
currently reports for the item (i.e. a re-class is pending). False when no
desired class is set, or it already matches the current one, or the item has
no synced class yet (that surfaces as not_synced instead).
137 138 139 140 141 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 137 def wayfair_class_diverged? desired = wayfair_desired_taxonomy_category_id current = wayfair_taxonomy_category_id_in_effect desired.present? && current.present? && desired != current end |
#wayfair_effective_taxonomy_category_id ⇒ Integer?
The taxonomy category we intend this item to carry — the desired override when
set, else the current synced category. The catalog update sender and listing
generator use it as attribute-schema context. Wayfair's item-update API does
not reclass an existing listing; a differing desired value remains the target
for reconciliation while the actual class change goes through support.
128 129 130 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 128 def wayfair_effective_taxonomy_category_id wayfair_desired_taxonomy_category_id || wayfair_taxonomy_category_id_in_effect end |
#wayfair_primary_product_url ⇒ String?
Get the first product URL from the array (typically US)
154 155 156 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 154 def wayfair_primary_product_url wayfair_product_urls&.first end |
#wayfair_product_url ⇒ String?
Wayfair product URL (if display_sku is available)
Format: https://www.wayfair.com/pd/product/W001498355.html
146 147 148 149 150 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 146 def wayfair_product_url return nil if wayfair_display_sku.blank? "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
169 170 171 172 173 174 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 169 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 ⇒ String?
Age of the last sync in human-readable format
160 161 162 163 164 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 160 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
106 107 108 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 106 def wayfair_synced? wayfair_synced_at.present? end |
#wayfair_taxonomy_available? ⇒ Boolean
Check if taxonomy category is set (required for attribute updates)
111 112 113 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 111 def wayfair_taxonomy_available? wayfair_taxonomy_category_id.present? end |
#wayfair_taxonomy_category_id_in_effect ⇒ Integer?
The current (synced) taxonomy category ID for this item — what Wayfair has it
classified as. Used to look up WayfairSchema for attribute definitions.
118 119 120 |
# File 'app/concerns/models/catalog_item_wayfair_helper.rb', line 118 def wayfair_taxonomy_category_id_in_effect wayfair_taxonomy_category_id || wayfair_class_id end |