# Marketplace orders

SyncSHOP brings orders from the marketplaces you sell on into the shop, and keeps their status in step on both sides.
eMAG comes first; others can be added as drivers.

## Switching eMAG on

In **Setări → Integrări** (Settings → Integrations), under **Marketplace-uri**, open **eMAG** and fill in:

- the **API user** and **API password** from your eMAG seller account;
- the **country** of the eMAG platform you sell on (`ro`, `bg` or `hu`; empty means Romania);
- optionally the **cancellation reason code** eMAG gets when you cancel one of its orders in the shop (empty: 1).

eMAG only answers servers on your account's list of allowed IP addresses: add the shop server's address there first.
**Testează conexiunea** (test the connection) tells you whether the user and password work.

The product code (*part number*) of each offer on eMAG must be the SKU of the variant in the shop: that is how an
order's products are found.

## What happens to an order

Every 5 minutes (*Sincronizează comenzile de pe marketplace* in Scheduled tasks; **Sincronizează acum** on the page
runs it at once), SyncSHOP:

1. **brings in the new orders**: each becomes a shop order with the marketplace's prices, delivery charge and vouchers,
   the buyer's billing and delivery address, and the stock reserved. The order's notes say which marketplace order it
   is (and the pickup point, for a locker delivery). An order paid online on eMAG comes in as **Plătită** (paid);
   cash on delivery and bank transfer as usual;
2. **accepts it on eMAG** (new → in progress), only once it is in the shop;
3. **reads back what changed on eMAG**: an order the buyer cancelled there is cancelled in the shop, and its stock
   released.

The marketplace writes to its own buyers, so the shop sends them no e-mails. You still get the new-order e-mail at the
shop's orders address.

As you work on the order in the shop, eMAG hears it: **În pregătire** (being prepared) becomes *prepared* there, and
**Expediată** (shipped) or delivered becomes *finalized*. Cancelling it in the shop cancels it on eMAG.

## When an order can't come in

**Comenzi de pe marketplace** (Admin → Marketplace, *Manages orders*) lists what came in, with the shop order it became
and its status on the marketplace. An order that couldn't come in is marked **Așteaptă** (waiting) with the reason:

- a **product code** the shop doesn't have: fix the SKU in the shop or the part number on eMAG;
- **not enough stock**: add stock, or settle the order on eMAG.

Waiting orders are tried again at every run, and stay new on eMAG until they are in, so nothing is accepted that the
shop can't fulfil. A status that couldn't be sent to eMAG is tried again too, and the page says so meanwhile.

Marketplace sales show as their own channel in the reports.

AWBs for eMAG orders are made as for any order (see [Orders](orders.md#awb)). Offers (price and stock on eMAG) are
still kept in the eMAG seller portal.

The eMAG driver follows eMAG's API documentation and is tested against simulated answers: confirm it on your seller
account with a first real order before relying on it.
