=== Multi-Store Stock Sync for WooCommerce ===
Contributors: catcodestudio
Tags: woocommerce, stock sync, inventory, multi store, sku
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Several WooCommerce stores, one warehouse: shared stock by SKU with a master store as the single source of truth, a retry queue and a sync log.

== Description ==

You sell the same goods on two or more WooCommerce sites — a retail and a wholesale domain, stores in different languages, a second brand. The warehouse is one, so the stock has to be one too. Multi-Store Stock Sync keeps it that way.

**How it works**

* One site is the **master**: its stock is the truth.
* Every other site is a **satellite**. Products are matched by SKU (simple products and variations).
* A sale, a cancellation, a refund with restock or a manual edit on a satellite goes to the master as an exact change (−2, +1…), with a unique event id. The master applies it with WooCommerce's own atomic stock update — at most once, whatever the retries.
* The master then sends the resulting number to every satellite. Each value carries a version, so an older value never overwrites a newer one.
* Values that came from the network never echo back, so two sites cannot ping-pong the same change.
* If the master is unreachable, changes wait in the queue and leave with retries; the satellite meanwhile shows "master stock + its own unsent changes".
* Nothing is sent from inside the checkout: deliveries run in the background right after the request.

**Features**

* Master / satellite roles, any number of satellites.
* One-paste connection: the master issues a connection key per satellite; every message is signed with HMAC-SHA256 and protected against replay.
* Stock sync by SKU for simple products and variations, including variations whose stock is kept on the parent product.
* Stock status sync for products without stock tracking.
* Sync log: what was sent or received, for which SKU, and how it ended.
* Connection status: last answer, last error, queue size, "check connection" and "send the queue now" buttons.
* Catalogue comparison: a satellite reads the master's catalogue, corrects every matching SKU and lists SKUs that exist on only one side.
* "Push all stock" from the master to a satellite.

**Where the data goes**

The plugin talks only to the other stores you connect yourself, over their REST endpoint `/wp-json/catcode-mss/v1/rpc`. It sends SKUs, stock quantities and stock statuses. No customer data leaves your stores, and nothing is sent to CatCode or any third party.

== Installation ==

1. Install and activate the plugin on every store of the network.
2. On the store whose stock is correct today, open WooCommerce → Multi-Store Sync and choose "Master (warehouse)".
3. Add a satellite and copy its connection key.
4. On the other store choose "Satellite" and paste the key. The satellite compares its catalogue with the master and takes over the master's stock for every matching SKU.

Make sure products carry the same SKU on all stores.

== Frequently Asked Questions ==

= What happens when two stores sell the last item at the same second? =

Both sales reach the master as separate changes and both are counted, so the master's stock goes below zero and every store shows the item as out of stock. Stock sync keeps the numbers right; it cannot stop two checkouts that finished before either sale reached the master (usually a few seconds).

= Does it sync orders or products? =

No. Every store keeps its own orders and product cards. Only stock is shared, matched by SKU.

= A product exists on only one store. =

Its stock stays local. The comparison report lists such SKUs on both sides.

= Do the clocks of the servers matter? =

Yes, a little: messages older than 5 minutes are refused as a replay protection. Keep the server time in sync (NTP), which every hosting does by default.

= Can a satellite run on OpenCart? =

The protocol is platform-neutral; an OpenCart module speaking the same protocol can join the network.

== Screenshots ==

1. Connections on the master: satellites, status, queue and the connection key.
2. The sync log.
3. The SKU report on a satellite.

== Changelog ==

= 1.0.1 =
* A SKU a satellite reported as missing is sent again as soon as the satellite has it (new product or edited SKU), after the satellite reconnects, and on "Compare with the master now" — no longer skipped for a day.
* Creating a product (or setting its SKU) on a satellite no longer adds its typed-in stock to the master: the satellite announces the SKU and takes the master's stock.
* A connection whose last exchange failed (for example, a server error on the other site) is no longer shown as "connected".

= 1.0.0 =
* First release: master / satellite roles, signed connection, stock sync by SKU with idempotent deltas and versioned values, retry queue, sync log, catalogue comparison and SKU report.
