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

Instance Method Summary collapse

Class Method Details

.wayfairsActiveRecord::Relation<Models::CatalogItemWayfairHelper>

A relation of Models::CatalogItemWayfairHelpers that are wayfairs. Active Record Scope

Returns:

See Also:



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

Returns:

  • (Boolean)


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_urlObject

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_urlObject

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

Parameters:

Returns:



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_ageObject

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

Returns:

  • (Boolean)


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)

Returns:

  • (Boolean)


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_effectObject

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