=== Factorize Watch ===
Contributors: webyoungstown
Tags: woocommerce, ebay, facebook, price-monitoring, competitors
Requires at least: 6.2
Tested up to: 6.7
Stable tag: 1.0.1
Requires PHP: 7.4
License: Factorize License (proprietary)
License URI: https://factorize.webyoungstown.com/license/

Read-only eBay price and listing-count watcher plus Facebook Page reader for WooCommerce. Daily market snapshots; never posts or lists anything.

== Description ==

If you run a liquidation, bin, discount, or open-box store, you are pricing against eBay every single day — but checking listing counts and price spreads by hand for your top products is tedious, and most "marketplace integration" plugins want write access to your accounts. Factorize Watch takes the opposite approach: it watches the outside market without ever touching it. Once a day (and on demand), it runs a GET-only eBay Browse API search for your most popular products and a GET-only read of your own Facebook Page posts, then shows everything on one admin screen next to your own prices. Nothing is ever listed, posted, edited, or deleted — every request the plugin makes is a GET.

= Features =

* **Daily eBay price sweep** — a WP-Cron event (`et_marketplace_sync`) sweeps your most popular products against the eBay Browse API on a configurable recurrence (daily by default).
* **Top-products targeting** — sweeps your 15 most popular products (configurable), ordered by the `et_popularity` product meta, so API calls go where they matter.
* **Live market stats per product** — for each product, records the active eBay listing count and the low, median, and high price computed from up to 50 live listings.
* **Side-by-side price table** — an admin table showing each product (linked to its edit screen), your WooCommerce price, active eBay listings, the eBay median, and the low–high spread.
* **Popularity refinement** — with eBay data present, each swept product's `et_popularity` score is recomputed as 75% industry heuristic plus up to 25 points of live market activity (500 active listings = full credit), clamped to 5–100. Sibling Factorize plugins sort by this meta.
* **Facebook Page reader** — GET-only Graph API read of your own Page's 10 latest posts (message, timestamp, permalink), listed on the same screen.
* **Read-only by design** — the plugin contains no write calls to either platform. It cannot list, relist, post, edit, or delete anything on eBay or Facebook.
* **Sync on demand** — a "Save & sync now" button runs the full sweep immediately, no waiting for cron.
* **Keys-later setup** — like a payment or SMTP plugin, the page renders a guided empty state until you paste credentials; nothing errors while keys are missing.
* **Clear error surfacing** — per-platform notices (`ebay_error` / `fb_error`) show the exact HTTP status or error message when a credential expires or a request fails.
* **Local, private storage** — the latest snapshot lives in a single WordPress option (`et_marketplace_data`); the only outbound traffic is the GET requests to eBay and Facebook using your own credentials. No third-party service, no telemetry.
* **Secure credential handling** — credentials are stored in their own option, entered through password fields, and the form is nonce-protected, sanitized, and gated behind the `manage_woocommerce` capability.
* **Factorize hub card** — registers an Insights card in the shared Factorize admin hub, including an at-a-glance "eBay key: connected / not set" status.
* **Clean uninstall** — deleting the plugin removes its options and clears its scheduled event, but deliberately keeps store data such as product popularity meta. Deleting a plugin should never delete store history.

= Works standalone, better together =

Factorize is a modular WooCommerce toolkit for liquidation, bin, discount, and open-box stores, built and battle-tested on a real 950-product store. Every plugin works completely standalone; any of them alone stands up the shared "Factorize" admin hub, and together they fill it with category tabs (Insights / Selling / Customers / Storefront). Factorize Watch lives under the Insights tab. If the Factorize analytics plugin is active, its industry-popularity heuristic feeds the refinement formula; without it, a neutral baseline is used and everything still works.

= Configuration =

Two behavior keys, read through `empire_market_config()`:

* `top_products` (default `15`) — how many of your most popular products are swept against eBay on each sync.
* `sync_recurrence` (default `daily`) — the WP-Cron recurrence name used when scheduling the sync event.

Override either by saving an array to the `factorize-watch_options` option (for example `update_option( 'factorize-watch_options', array( 'top_products' => 25 ) )`) or by filtering the merged config at runtime with the `factorize-watch_config` filter. Credentials are not part of this config: the eBay OAuth token, Facebook Page ID, and Facebook Page access token are managed on the plugin's own admin page and stored in the `et_marketplace_settings` option. The latest snapshot is stored in `et_marketplace_data`.

= Roadmap =

The following features are planned and are NOT in this release yet:

* Price-match alerts
* Competitor watchlists
* Automatic repricing suggestions
* Facebook catalog feed export
* Google Shopping feed
* Daily email summary

== Installation ==

1. Upload the `factorize-watch` folder to `/wp-content/plugins/`, or install through the Plugins screen, then activate it. WooCommerce should be active for the price table.
2. A "Factorize" menu appears in the admin sidebar (any Factorize plugin creates the hub). Open **Factorize → Marketplace**.
3. Get an eBay OAuth token for the Browse API (developer.ebay.com → your app → OAuth) and paste it into the Credentials form. This unlocks the eBay price sweep.
4. Optionally add your Facebook Page ID (or name) and a Page access token with the `pages_read_engagement` permission to unlock the Page posts reader. You can add either platform's keys alone.
5. Click **Save & sync now** for your first snapshot. After that, the data refreshes automatically on the configured schedule (daily by default; the first automatic run is scheduled about an hour after activation).

== Frequently Asked Questions ==

= Does it work without the other Factorize plugins? =

Yes. It is fully standalone and even creates the Factorize admin hub on its own. If the Factorize analytics plugin is also active, its industry-popularity heuristic is used when refining product scores; without it, a neutral baseline of 50 is used and everything else behaves identically.

= Will it ever post, list, or change anything on eBay or Facebook? =

No. Every request the plugin makes is a GET — eBay Browse API searches and a read of your own Facebook Page's posts. There is no code path that writes to either platform.

= Where does my data live? =

Entirely in your WordPress database: credentials in the `et_marketplace_settings` option, the latest snapshot in the `et_marketplace_data` option, and refined popularity scores in the `et_popularity` product meta. There is no custom table and no external storage.

= Does anything leave my server? =

Only the outbound GET requests to `api.ebay.com` and `graph.facebook.com`, made with the credentials you provided. There is no telemetry, no phoning home, and no third-party service in between.

= How do I change how many products are swept, or how often? =

Save an array to the `factorize-watch_options` option (keys `top_products`, `sync_recurrence`) or use the `factorize-watch_config` filter. Note that the cron event is scheduled once — if you change `sync_recurrence` afterward, delete the existing event (`wp cron event delete et_marketplace_sync`) so it is re-scheduled with the new recurrence.

= Do I need WooCommerce? =

Yes, in practice. The sweep targets WooCommerce products and the comparison table uses WooCommerce price formatting. The Facebook Page reader itself has no WooCommerce dependency.

== Screenshots ==

1. The Marketplace Monitor screen: read-only notice and the Credentials form (eBay OAuth token, Facebook Page, Facebook token) with Save and "Save & sync now" buttons.
2. The eBay comparison table: your top products with your price, active listing count, eBay median, and low–high spread, each linked to its product editor.
3. The Facebook section: your Page's latest posts with text snippets and permalinks, straight from the Graph API.
4. The guided empty state before any keys are pasted — nothing to configure elsewhere, no errors.
5. The Factorize hub's Insights tab with the Factorize Watch card and its "eBay key: connected" status line.

== Changelog ==

= 1.0.0 =
* Initial release.
* Daily GET-only eBay Browse API sweep of your most popular products: active listing counts plus low/median/high prices.
* Side-by-side admin table comparing your WooCommerce prices against the live eBay market.
* Popularity refinement: live listing counts blend into each product's `et_popularity` score.
* GET-only Facebook Graph API reader for your own Page's latest posts.
* Keys-later credentials page with on-demand "Save & sync now", per-platform error notices, and a Factorize hub card.
