=== 2khat Catalog Sync ===
Contributors: mohammad61
Requires at least: 5.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Official WooCommerce catalog sync plugin for the 2khat platform.

== Description ==

2khat connects your WooCommerce store to the 2khat platform by exposing a secure, paginated REST API for product catalog synchronization.

After registering your store with the 2khat team, install and activate this plugin to allow 2khat to fetch your published products and variations.

== Installation ==

1. Upload the `2khat` folder to `/wp-content/plugins/`.
2. Activate the plugin through the WordPress Plugins screen.
3. Ensure WooCommerce is installed and active.
4. Confirm `public_key.pem` is present in the plugin directory.

== Security ==

`public_key.pem` is the 2khat RSA public key used to verify API request signatures. It is not a private credential and must remain in the plugin directory.

== Authentication ==

All 2khat API requests require RSA domain signature verification.

**Signing (2khat server side):**

1. Normalize the store domain: use the host from `site_url()`, without a `www.` prefix.
2. Sign the domain string with the 2khat private key using SHA256.
3. Base64-encode the binary signature.
4. Send it in the request header:

`Authorization: Twokcs <base64-signature>`

Legacy clients may also use `Authorization: Basic <base64-signature>` during migration.

**Example (OpenSSL CLI):**

```
echo -n "example.com" | openssl dgst -sha256 -sign 2khat_private.pem | openssl base64 -A
```

== REST API ==

**GET** `/wp-json/twokcs/v1/version`

Returns the plugin version.

**GET** `/wp-json/twokcs/v1/products?page=1&per_page=100`

Returns paginated published products with nested variations.

**GET** `/wp-json/twokcs/v1/categories?page=1&per_page=100`

Returns paginated product categories.

**GET** `/wp-json/twokcs/v1/attributes?page=1&per_page=100`

Returns paginated product attributes.

**GET** `/wp-json/twokcs/v1/attribute-terms?page=1&per_page=100`

Returns paginated attribute terms across all attributes. Optionally filter by attribute:

**GET** `/wp-json/twokcs/v1/attribute-terms?attribute_id=1&page=1&per_page=100`

**GET** `/wp-json/twokcs/v1/variants?product_ids=10,20`

Returns compact published variants grouped by parent product ID. Each item includes `product_id` and a `variants` array with: `id`, `on_sale`, `status`, `price`, `regular_price`, `sale_price`, `stock_quantity`, `stock_status`.

**GET** `/wp-json/twokcs/v1/variants?ids=305,306,307`

Returns compact published variants for the given variation IDs in request order. Response shape: `{ count, results: [...] }` with the same variant fields as above.

**GET** `/wp-json/twokcs/v1/variant?id=305`

Returns a single compact published variant object with the same fields as above. Returns 404 when the variation is missing or not published.

Query parameters (all catalog endpoints):

* `page` — page number (default: 1, minimum: 1)
* `per_page` — items per page (default: 100, maximum: 200)
* `attribute_id` — (attribute-terms only) filter terms to a single attribute
* `product_ids` — (variants only) comma-separated parent product IDs; returns variants grouped by product
* `ids` — (variants only) comma-separated variation IDs; returns a flat list in request order
* `id` — (variant only) single variation ID
* `debug` — include SQL query stats only when `WP_DEBUG` and `TWOKCS_DEBUG` are enabled, or when the `twokcs_allow_debug` filter returns true. Full query details require `SAVEQUERIES` enabled in `wp-config.php`.

== Changelog ==

= 1.0.6 =
* Align text domain with WordPress.org slug `2khat-catalog-sync`

= 1.0.5 =
* Rename all plugin globals from `dokhat` to `twokcs` prefix for WordPress.org compliance
* Update REST namespace to `twokcs/v1` and auth scheme to `Twokcs`

= 1.0.4 =
* Align plugin folder and main file name with WordPress.org slug `2khat`
* Fix auth header documentation to match the `Dokhat` scheme accepted by the plugin

= 1.0.3 =
* Rename display name to 2khat Catalog Sync (WordPress.org trademark requirement)

= 1.0.2 =
* Rename plugin for WordPress.org compliance (2khat WooCommerce Catalog Sync)
* Remove runtime SAVEQUERIES global side effects from debug mode
* Document public_key.pem as intentional RSA public key

= 1.0.1 =
* Align plugin metadata for WordPress.org submission

= 1.0.0 =
* Initial 2khat release
* Modular plugin architecture
* RSA domain authentication with 2khat key pair
* Optimized bulk product export endpoint
* Compatibility with Discount Rules for WooCommerce and Woodmart theme
