Connecting 1C
In 1C, create an exchange node with a site and give it three things:
Адрес сайта: https://your-shop/commerceml
Имя пользователя: anything
Пароль: an API token
The address https://your-shop/1c_exchange.php answers exactly the same — a
decade of 1C configurations, articles and support scripts have that path
hard-coded, and a shop moving from another engine should be able to paste in the
address it already has.
The old address, and the one file this module writes
That second spelling needs a file to exist. Web servers hand a .php address to
PHP only when the file is really there and answer 404 otherwise, so the request
never reaches the shop’s own code no matter what its routes say — the one
address the module cannot help being asked for is the one it would never hear.
So installing this module writes public/1c_exchange.php: eleven lines that
correct SCRIPT_NAME and hand the request to the shop’s front controller.
Uninstalling deletes it. That is the only file this module puts outside its own
directory, and it is deleted by content, never by name — if something else is
already living at that address (the engine you are migrating away from, most
likely) it is left exactly where it is and the exchange screen says so.
The screen shows the state of the address and can put the file back or take it away. Take it away if you would rather write a rewrite rule of your own:
# nginx
rewrite ^/1c_exchange\.php$ /index.php last;
Why a token and not a password
This credential goes into a settings file on somebody’s accounting machine and stays there for years. A person’s password is the wrong thing to put there: it cannot be revoked without locking that person out, it grants everything they can do for ever, and it is one screenshot away from being everyone’s.
So the password field takes an API token (Admin → API tokens). It must be allowed to write, and its owner must hold “Set up the 1C exchange”. Revoking it stops the exchange and nothing else. The user name is ignored — 1C insists on one, the token already says who this is, and making them agree would only invent a way to fail.
What happens on the wire
Worth knowing, because nothing about it is guessable and every symptom looks the same from 1C’s side:
?type=catalog&mode=checkauth— the shop answerssuccess, a cookie name and a cookie value. That value opens a conversation: it addresses the directory the files will land in.?mode=init— the shop says whether it can unzip and the largest chunk it will take. 1C splits bigger files itself.?mode=file&filename=import.xml— one chunk per request, appended. Images arrive the same way, underimport_files/.?mode=import&filename=import.xml— a batch of products, thenprogress. 1C asks again. And again, until the shop answerssuccess.
That last step is why there is no queue worker in any of this: the protocol was built to be sliced, and an exchange that depended on a worker nobody started would say “in progress” for ever. If the import times out, lower Products per request in the module’s settings.
Every answer is a bare word on the first line and a message on the second. If 1C reports a failure with no explanation, something in front of the shop is answering instead of it — a maintenance page, a login redirect, a proxy error. The exchange log (Admin → 1C exchange) shows what actually arrived.
The first exchange
Set Products → Nothing — receive and record, change nothing before the first run.
That first exchange then writes no products at all. What it does do is fill the matching screen with everything 1C sent — its price types, its characteristics, its variants — so you can see the real vocabulary of your own 1C before it is allowed to touch anything. Then match what should be matched, turn the strategy up, and run it again.
What matches what
Two ways a thing is recognised
By its own identifier, where the shop has a column for one. Products,
categories, warehouses, orders and customers all carry external_id, and the
1C identifier goes there. That is the shop’s convention for every exchange, not
this module’s, and it is why renaming a category on either side breaks nothing.
Through the matching screen, where the shop has no such column. Characteristics, their values and price types belong to the catalogue module, and a module does not add columns to another module’s tables. Their link lives in this module’s own, which is also the only place that can hold seen, and not decided about yet — which is what makes that screen a queue rather than a form.
The first exchange on a catalogue that already exists
An existing product has no 1C identifier, so there is a one-time bridge: Recognise a product by its article number and Recognise a category by its name. Both apply only to rows that have no identifier yet. Once matched, the identifier is written onto the row and the bridge is never used for it again.
A category that already belongs to a different 1C group is not a candidate, however alike the names.
The three answers
Every row on the matching screen offers the same three, plus the shop’s own things to point at:
- not decided — the default, and it means skipped. Nothing carrying this is imported. The exchange counts them and says so in the message 1C prints.
- Create one at the next exchange — make it in the shop, using 1C’s name, and link the two.
- Never import this — a permanent no. Different from “not decided” only in that it stops the row nagging.
A characteristic’s values are listed under it and saved with it, because “import this characteristic, and these of its values” is one decision. A value cannot be created before its characteristic is — it has nowhere to hang — so it stays in the queue under a parent that is still unanswered.
Price types, and the thing that goes wrong
ТипыЦен is the part that can do real damage. A shop sells at retail and buys
at wholesale, and 1C sends both down the same wire with nothing but an
identifier to tell them apart. An importer that takes “the first price it finds”
will, one day, publish the purchase price.
So an unmatched price type writes nothing. Not the base price, not a guess.
What a 1C price type can point at is either one of your own price types, or one of three columns:
| Local side | Fills |
|---|---|
| The base price | price — what the product sells for |
| The old (struck-through) price | list_price |
| The cost price | cost_price — never shown to a customer |
The money then goes through the shop’s own pricing: 1C sends major units and names a currency, and what is stored is the typed number in that currency plus a books amount derived from it — exactly as if a person had typed a price in euro into the product form. A later change to the exchange rate reprices it correctly, which writing the column directly would not.
Attributes: ЗначенияРеквизитов
Everything CommerceML has no element for lives in a bag of named attributes, and the names are whatever that installation calls them: “Вес”, “Вес, кг”, “ВесБрутто”, “Масса”. There is no canonical spelling to guess, so the module’s settings take a list of names per field, one per line, and the last one actually present wins. Weight is read in kilograms, dimensions in centimetres, and both are stored the way this shop stores them everywhere — whole grams and whole millimetres.
What an exchange will not overwrite
The settings that matter most are the ones about not writing, because an exchange runs unattended and nightly against a shop somebody arranged by hand:
- Fill these on the first import only — names and descriptions are ticked by default. What the copywriter rewrote survives tonight.
- Photographs → Ignore is the default. “Replace” destroys, every night, the photographs the shop took itself.
- A product 1C has just created is → Hidden. It arrives with no photograph, no storefront copy and no category of yours; a person should choose when it goes on sale.
- A product 1C marks
Удаленis disabled, never deleted. The URL stays reachable, old orders stay readable, and a deletion sent by mistake is one click to undo.
Orders
The catalogue comes in; the orders go out. 1C asks for them with
type=sale&mode=query, reads the file, and says success when it has taken
them. It can then send documents back, the same way it sends a catalogue — a
file, then an import — and those may change two things about an order and
nothing else.
Which orders go
Admin → 1C exchange → Orders and what 1C may change.
There is no default that suits every shop, so the condition is stated on the two axes an order already has:
- statuses — the shop’s own workflow. Tick the ones that mean “this order is real”: Processing for a shop whose manager confirms orders, Open for one that trusts the checkout.
- paid — the second axis, which is not a status. A prepaying shop writes goods off in 1C when the money arrives, whatever the order’s status is.
- either / both, and a date before which nothing is sent. The date is what a shop connecting 1C to two years of existing orders needs on the first night.
Tick nothing and nothing is sent. That is deliberate: an unanswered question is not the same as “send everything”, and the alternative writes stock off in 1C for orders nobody has confirmed.
An order is offered again whenever anything on it changes, and never offered
twice for nothing — the marker is a hash of the document itself, so any change
to what would be sent sends it, and no list of “fields that count” has to be
maintained. Nothing is marked as taken until 1C says success, so an exchange
that dies halfway loses nothing.
What the document contains, and why it adds up
Every line of an order becomes a <Товар>, identified by the product’s
external_id. A product 1C has never sent carries a fallback identifier of
ours: 1C will not match it, which is correct — it genuinely is not in their
nomenclature — and matching by name instead would invent links between things
that happen to share a word.
Delivery is a line, and so is anything else charged on top (a tax added at checkout, a fee). The sum of the lines, less the discount, is the order’s total by construction. Dropping the delivery line — tempting, since a parcel carrier is no business of 1C’s — is what produces documents an accountant has to correct by hand a week later.
The delivery line’s identifier is set per method, on the delivery method’s own page (1C: delivery service identifier), with a fallback on this screen. A method with neither still exports, by name and without an identifier.
The money is the shop’s books. Every amount on the order is in the shop’s own currency and consistent with every other. What the customer was quoted in, and what their bank was charged, are written into the attributes for anyone who wants them — never used as the document’s own numbers, or the lines would stop adding up to the total.
The buyer
1C wants a counterparty, and most orders have no account behind them. Each order
carries a short reference for its buyer, derived from the strongest thing known
about them — the account, else the phone number, else the email — so two orders
from one person are one counterparty in 1C. A phone typed as +380 67 123-45-67
one day and 0671234567 the next is the same buyer.
No throwaway accounts are created. If 1C insists on an email address for a buyer who never gave one, fill in Made-up email domain and the export composes one from the reference; the shop’s own record still says, truthfully, that it has no email for that person.
What 1C may change coming back
The status, and the fact that the money arrived. Nothing else.
1C legitimately holds a document with different lines on it — a warehouse ships nine of the ten, an accountant corrects a price. Importing that would mean a nightly exchange silently changing the total of an order the customer has already agreed to, and possibly already paid. A shop that wants more than this has Automations, where the rule is written down, visible and logged.
Both facts are read by attribute NAME, from a list typed in the settings, for
the same reason weights are: no two 1C installations spell them alike. An
attribute that is present but empty, or says Нет, is not an event — otherwise
the first exchange marks every order shipped.
- Shipment moves the order to the status chosen on this screen (Shipped by default). Through the shop’s own status change, so the warehouse moves with it.
- Payment settles the order through the same code the manager’s mark as paid runs. It is not a status here — payment is the second axis — and an order already paid is left alone.
An order is found by its identifier first and its number second. An order matched by number acquires 1C’s identifier on the way past, which is how a shop whose orders predate the exchange gets linked, one document at a time.
What the screen shows
The table at the bottom is the ledger: when each order was offered, whether 1C has taken it, and what it last said about it. “1C answered, and said nothing had shipped” is the answer a shop wondering why an order is still open actually needs, so it is recorded whether or not anything moved.