Skip to main content

NFusion Pricing Sync

The NFusion Pricing Sync system is the core function of the Middleware Platform. It periodically fetches live spot prices and markups from the nFusion Solutions precious-metals API and pushes them to the Retail WooCommerce site, the Dealers WooCommerce site, and/or Algolia search indices.


How It Works

nFusion API (per-tenant base URL)

│ GET /service/Price/PricesByChannel

NFusionService::getPrices()
│ Returns array of { sku, ask, bid, wholesale_ask, wholesale_bid, tiers, ... }

PriceSyncService::syncPricesForTenant()

├──▶ AlgoliaSyncTargetProvider::sync() → updates Algolia index records
├──▶ WooCommerceSyncTargetProvider::sync() → writes wp_postmeta rows directly
└──▶ HttpSyncTargetProvider::sync() → POST/PUT/PATCH to a custom endpoint

Multi-Tenant Architecture

The system supports multiple tenants — each tenant corresponds to one nFusion account. Common tenants:

TenantDescription
RetailScottsdale Mint retail WooCommerce store
DealersWholesale dealer WooCommerce store

Each tenant has:

  • Its own nFusion API alias ({alias}.nfusioncatalog.com)
  • Its own API token (stored as an env-var name in the database)
  • Its own sales channel and currency
  • One or more Sync Targets (described below)

Sync Targets

Each tenant can have multiple sync targets. A sync target defines:

  • TypeWooCommerce, Algolia, or HTTP
  • Settings — provider-specific configuration (DB connection, index name, endpoint URL, etc.)
  • Active flag — disabled targets are skipped
  • Dry-Run flag — runs the sync logic without writing to the destination

Schedule

The sync runs on a cron-style schedule (default: every 5 minutes) via the Laravel scheduler. Each run:

  1. Loads all active tenants (NFusionTenant::active())
  2. For each tenant, dispatches NFusionSyncTenantPricesJob onto the nfusion queue
  3. Each job fetches prices once and iterates all active sync targets

Sync Logs

Every sync run creates an NFusionSyncLog record with:

  • Start/end timestamps
  • Status (runningsuccess / partial / error)
  • Attempted and processed SKU counts
  • Detailed per-SKU items in NFusionSyncLogItem

Logs are viewable in the Filament admin under nFusion → Sync Logs.


Key Files

FileDescription
app/Services/NFusionService.phpAPI client — fetches prices from nFusion
app/Services/PriceSyncService.phpOrchestrator — iterates tenants and targets
app/Jobs/NFusionSyncTenantPricesJob.phpQueued job wrapper
app/SyncTargets/Provider implementations
app/Models/NFusionTenant.phpTenant model
app/Models/NFusionSyncTarget.phpSync target model
app/Models/NFusionSyncLog.phpSync log model
config/nfusion.phpTimeout and global nFusion settings