# 👁️ Factorize Watch

> Watches eBay and Facebook so you don't have to. Read-only, always.
>
> **Suite identity:** icon 👁️ · accent `#7a9e4e` · part of the [Factorize suite](../README-FACTORIZE.md)

## What it does

Read-only market watcher for the store. Once a day (and on demand via the admin page's "Save & sync now" button) it runs a GET-only eBay Browse API search for the store's most popular products, recording live listing counts and price spreads (low / median / high), and reads the latest posts from the store's own Facebook Page via the Graph API. It never lists, posts, edits, or deletes anything on either platform. When eBay data is present, live listing counts also gently refine each product's `et_popularity` score (75% industry heuristic + up to 25 points of live market activity).

## Configuration

| Key | Default | Effect |
| --- | --- | --- |
| `top_products` | `15` | How many of the most popular products (ordered by the `et_popularity` post meta, descending) are swept against eBay on each sync. |
| `sync_recurrence` | `daily` | WP-Cron recurrence passed to `wp_schedule_event()` for the `et_marketplace_sync` event. Must be a registered cron schedule name. |

Override defaults either by saving an array to the `factorize-watch_options` option (e.g. `update_option( 'factorize-watch_options', array( 'top_products' => 25 ) )`) or by filtering the merged config at runtime with the `factorize-watch_config` filter. Reads go through `empire_market_config( $key )` in `config.php`. The legacy `empire-marketplace-monitor_options` option is still read as a fallback when `factorize-watch_options` is empty.

Note on the cron schedule: the sync event is scheduled once (on `init`, when no event exists). If you change `sync_recurrence` after the event has been scheduled, clear the existing event (`wp cron event delete et_marketplace_sync`) so it is re-scheduled with the new recurrence.

**Credentials are NOT in this config.** The eBay OAuth token, Facebook Page ID, and Facebook Page access token live in the existing `et_marketplace_settings` option and are managed through the plugin's own admin page (Factorize → Marketplace → Credentials form). The latest snapshot is stored in the `et_marketplace_data` option.

## Works with

- **The Factorize hub**: ships its own guarded copy of `suite-hub.php`, so even installed alone it stands up the shared Factorize admin area and registers its Insights card (with an "eBay key: connected / not set" status line). Its admin page is a submenu of the hub (`empire_suite_parent_slug()` → `factorize`, page slug `et-marketplace`).
- **The Factorize analytics plugin**: calls `empire_tools_popularity_score()` (from that plugin) when refining product popularity; if absent, a neutral heuristic of 50 is used. Degrades gracefully without the sibling plugin.
- **WooCommerce**: the sync queries `product` posts, and the admin page uses `wc_get_product()` / `wc_price()` to display your prices. The rendered eBay table requires WooCommerce to be active.
- Writes the `et_popularity` post meta, which sibling Factorize plugins read/sort by.

## Hooks it registers

- `admin_menu` (priority 20) — adds the Marketplace admin page as a submenu of the Factorize hub.
- `admin_init` — registers the plugin's card with the Factorize hub.
- `init` — schedules the `et_marketplace_sync` cron event (recurrence from config, default daily) if not already scheduled.
- `et_marketplace_sync` — cron hook; runs `empire_tools_marketplace_sync()`.
- Provides filter `factorize-watch_config` — lets code override the merged config array.

## Publishing

`readme.txt` (WordPress.org listing format) and `QUICKSTART.md` (5-minute setup guide) live alongside this file and are the source material for the WordPress.org listing.
