=== Datie – Sync with MoySklad for WooCommerce ===
Contributors: kinokentij
Tags: moysklad, inventory, stock sync, orders, erp
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Syncs products, prices, stock and images from MoySklad to WooCommerce and sends store orders to MoySklad.

== Description ==

Datie connects a WooCommerce store to [MoySklad](https://www.moysklad.ru/), a cloud inventory and trade management service popular in Russia and the CIS. MoySklad stays the source of truth for the catalog; the store gets products, prices and stock from it, and MoySklad gets the orders.

Datie is an independent plugin. It is not affiliated with, endorsed by or sponsored by Lognex LLC (MoySklad), WooCommerce or Automattic; their names are used only to describe what the plugin works with.

The plugin works through the MoySklad JSON API 1.2 with an access token. Everything runs on the site side: there is nothing to install or configure in MoySklad apart from creating the token.

= Catalog =

* Products, variants (MoySklad modifications), bundles and services.
* Categories from MoySklad product groups, or brand, categories and tags from custom fields.
* The main image and the gallery in MoySklad order.
* The price type and the sale price type of your choice; foreign-currency prices are converted at the MoySklad rate.
* Stock — total or for one warehouse, with or without reserved quantities.
* Weight, dimensions and the custom fields you select as product attributes.
* VAT rates mapped to WooCommerce tax classes.
* Products that disappear from MoySklad are moved to drafts — and come back when they reappear. If MoySklad returns nothing at all, hiding is cancelled, so an outage never empties the store.

= Orders =

* Store orders go to MoySklad through a background queue; checkout is not slowed down by the API.
* The customer is found by email and, optionally, by phone; empty fields of the MoySklad card are filled from the order.
* Order number from MoySklad, or a prefix for site orders.
* Shipping is sent as a MoySklad service line, per shipping method.
* Statuses in both directions; changes made in MoySklad come back to the site through a webhook.

= Background work and diagnostics =

* Full sync on a schedule plus a quick check for changes every few minutes.
* Work is done in batches with Action Scheduler and resumes after interruptions.
* A live progress indicator on the overview page.
* The “Needs attention” list collects failures that need a human: a stopped sync, an order that did not reach MoySklad, a SKU already used by another product.
* Errors are always written to the WooCommerce log; a verbose log can be switched on for troubleshooting.
* Site Health checks the access token and the order webhook.

= Interface language =

The interface is in English and Russian. The Russian translation ships with the plugin.

== External services ==

This plugin relies on MoySklad, a cloud inventory and trade management service provided by Lognex LLC. Connecting a WooCommerce store to MoySklad is the purpose of the plugin. It contacts nothing until you enter a MoySklad access token in its settings, and it contacts no other services.

= MoySklad JSON API (api.moysklad.ru) =

Used to read the catalog from MoySklad and to send store orders to it.

* Every request carries your MoySklad access token.
* Catalog sync — on the schedule you set or when you start it manually: the plugin requests products, variants, bundles, services, product groups, prices, stock, images and custom fields. No store or customer data is sent.
* Order transfer — when an order is created or updated on the site: the order number, date, line items, prices, VAT, shipping, the customer's name, email, phone and address, the customer note and a link to the order in the store admin. To find an existing customer, the email and, if enabled, the phone number are sent as a search query.
* Status sync from the site — if enabled, when an order status changes: the new order status.
* Status sync from MoySklad — if enabled: the plugin registers a webhook with your site's REST API address and a secret key, and MoySklad sends order change notifications to it.

= MoySklad file storage =

Product images are downloaded by the links that the MoySklad API returns. Only the download request is made; nothing about the store is sent.

= MoySklad web application (online.moysklad.ru) =

The plugin shows links to the MoySklad web application, for example "Log in to MoySklad" and "View the product in MoySklad". They open in your browser only when you click them; the plugin itself sends nothing there.

The service is provided by Lognex LLC: [MoySklad Terms of Use (public offer)](https://www.moysklad.ru/oferta/), [MoySklad Privacy Policy](https://www.moysklad.ru/upload/files/policy.pdf). API documentation: [dev.moysklad.ru](https://dev.moysklad.ru/doc/api/remap/1.2/).

== Installation ==

1. Install and activate WooCommerce.
2. Install Datie from the Plugins screen, or upload the `datie` folder to `/wp-content/plugins/`, and activate it.
3. In MoySklad, create an access token in the API access section. A separate user with rights only to products and orders is the safest choice.
4. In WordPress, open MoySklad → Settings, paste the token and save.
5. Go through the settings sections, then start the first sync from MoySklad → Overview.

If you used the WooMS plugin before, Datie picks up its data and links the existing products instead of creating them again. Back up the database first.

== Frequently Asked Questions ==

= Does it need anything on the MoySklad side? =

Only an access token. Webhooks for status sync require a paid MoySklad plan.

= Which products are synced? =

All products by default. You can limit the sync to selected product groups, skip products without a SKU, or mark products with a MoySklad checkbox field so they are not loaded.

= How are existing store products matched? =

By the MoySklad ID saved on the product, then by SKU (or by the MoySklad code, if you choose so in the settings). The product name and description on the site are overwritten only if you enable that.

= What happens if MoySklad is unavailable? =

The sync stops with an error and resumes on the next run. Products are not hidden because of an outage, and orders wait in the queue.

= Where are the logs? =

In WooCommerce → Status → Logs; each part of the plugin writes to its own source. Failures that need attention are also listed on the plugin overview page.

= Where can I get help? =

On the plugin support forum, or contact the developer via Telegram: https://t.me/kinokentij

== Screenshots ==

1. Overview: sync progress, the “Needs attention” list and quick links.
2. Settings: connection and sync schedule.
3. Settings: which products are synced and what happens to missing ones.
4. Settings: product groups, brand, categories and tags.
5. Settings: order transfer to MoySklad.
6. Settings: order status mapping from MoySklad to the store.

== Changelog ==

= 1.0.0 =
* First release in the WordPress.org directory.
* Interface in English with a bundled Russian translation.
* Orders are sent through a background queue; the MoySklad order number arrives in the first customer email.
* Customer lookup by phone; duplicate customers are reported.
* VAT rates from MoySklad, including 22% and variants.
* Bundles and services follow the common product path; one hiding pass after a full sync.
* Protection against hiding the whole catalog during a MoySklad outage.
* Order queries work with both HPOS and the legacy order storage.
* After a MoySklad failure, bundle and service walks retry in 5 minutes instead of on every page load.
* New admin interface with a live progress indicator and the “Needs attention” list.
* Errors are always logged; verbose logging is optional.

== Upgrade Notice ==

= 1.0.0 =
First WordPress.org release. Settings are kept; if you update from a manually installed copy, replace the whole plugin folder.
