Skip to content

Synchronization

“SilentJMA” edited this page Jun 18, 2026 · 1 revision

Synchronization

The plugin provides bidirectional data synchronization between WooCommerce and Mirakl. All syncs are cron-driven with configurable intervals and manual triggers from the admin.

Order Import

Direction: Mirakl → WooCommerce

Orders placed on the marketplace are fetched via the Mirakl OR01/OR11 APIs and created as WooCommerce orders.

  • New orders are created as on-hold in WooCommerce
  • WooCommerce customer emails are suppressed for Mirakl-imported orders (the marketplace handles customer communication)
  • Orders are tracked in the mirakl_orders table for status mapping
  • Shipping updates (carrier code, tracking number) can be sent back to Mirakl when the order status changes to completed

Status Transitions

WooCommerce Status Mirakl Action
completed Triggers shipping notification to Mirakl
cancelled Can trigger order refusal via admin action
Manual ship action Update tracking info via OR24/OR25

Stock Sync

Direction: WooCommerce → Mirakl

Product stock quantities are pushed to Mirakl via the ST01 API.

  • Only products marked as active for Mirakl sync (meta: _mirakl_active = 'yes') are included
  • Stock quantities are resolved using the OF21-backed offer SKU cache
  • Aside-inventory reservation rules are applied via effective_stock_quantity()
  • The sync runs per-store and processes all active products

Inventory Rules

The effective_stock_quantity() method applies:

  • Subtract aside-inventory reservations
  • Respect minimum stock thresholds
  • Apply per-product adjustments from the _mirakl_stock_adjustment meta

Price Sync

Direction: WooCommerce → Mirakl

Prices are pushed to Mirakl via the PRI01 Pricing Import API. This is a bulk import workflow:

  1. Submit — WooCommerce prices are formatted into rows and submitted via POST /api/pricing/imports
  2. Track — An import record is created in the mirakl_pricing_imports table with status pending
  3. Poll — The import status is polled periodically (poll_pending_imports()); on completion, the record is updated with success/failure counts
  4. Error Report — Failed rows include error details from the Mirakl error report

Pricing Import Sources

Source Trigger
cron Automatic cron job
manual Manual price sync from admin

Pricing Import Statuses

Status Description
pending Submitted, awaiting processing
running Being processed by Mirakl
completed Successfully processed (may have errors)
failed Import rejected
cancelled Import cancelled

Product Import / Export

Direction: Bidirectional

Export (WooCommerce → Mirakl)

Products are exported via the OF24 API:

  • Filters products with _mirakl_active = 'yes'
  • Resolves WC SKU → Mirakl shop SKU via the offer SKU cache
  • Includes: price, stock, images, categories, brand (_mirakl_brand), and GTIN (_mirakl_gtin)
  • The format_product_for_mirakl() method structures data for the API

Import (Mirakl → WooCommerce)

Note: Product import from Mirakl is available but less commonly used. Configured via Sync Schedule.

Tracking Updates

Direction: WooCommerce → Mirakl

When a Mirakl order is shipped in WooCommerce (status changes to completed or manual ship action):

  1. Carrier code and tracking number are captured from the order meta (_carrier_code, _tracking_number)
  2. Data is sent to Mirakl via the OR24/OR25 API
  3. Update time is recorded in mirakl_tracking_update_times for incremental sync

Cron System

Custom Intervals

Registered on plugin activation:

Interval Schedule Name
5 minutes mirakl_5min
10 minutes mirakl_10min
15 minutes mirakl_15min
30 minutes mirakl_30min
1 hour hourly (WordPress default)

Cron Hooks

Hook Method Controlled By
mirakl_connector_orders_import_cron cron_orders_import() mirakl_orders_sync_enabled
mirakl_connector_tracking_update_cron cron_tracking_update() Same as orders
mirakl_connector_auto_stock_sync_cron cron_auto_stock_sync() mirakl_stock_sync_enabled
mirakl_connector_prices_sync_cron cron_prices_sync() mirakl_price_sync_enabled
mirakl_connector_products_sync_cron cron_products_sync() mirakl_products_sync_enabled

Sync Lock

To prevent concurrent runs, each store+type combination has a TTL-based lock (Mirakl_Sync_Lock). If a sync is still running when the next cron tick fires, the second run is skipped. The lock automatically expires after 360 seconds (configurable).

Sync Logs

Every sync operation is recorded in the mirakl_sync_history table. View logs at Mirakl → Sync Logs. Entries are filterable by:

  • Store name
  • Sync type (order, product, stock, price, offer, return)
  • Status (success, failed, pending)
  • Date range

Each log entry stores the Mirakl ID, WooCommerce ID, and error message (if applicable).

Clone this wiki locally