Import
Data exchange → Import takes a CSV, XML or YML file — your own export coming back, a supplier’s price list, another engine’s catalogue — and writes its rows into the shop: products, categories, characteristics and the rest of the list.
Changing many products at once
Names, addresses, descriptions, categories, prices, stock, characteristics: for a hundred products a file is quicker than a hundred forms.
- Export the products with the columns you are going to change (an export
profile in CSV), or write the file yourself: a
skucolumn and the columns to change. - Change the cells in a spreadsheet and save it as CSV.
- Import it. A row finds its product by External ID, then by SKU. Only the columns the file has are written; everything else stays as it was.
A changed address keeps the old one as a redirect, as the product form does. A row whose SKU matches no product makes a new one — unless Create what is not found is off, and then it is skipped. A new product needs a name: a row without one is skipped and named in the result, and the rest of the file goes in.
Orders
Orders are exported, not imported. A status and a payment are changed on the order’s page (or for many orders at once in the list), by a CRM through the API, or by the 1C exchange — always by the same code as in the admin, so the stock, the order’s history and the customer’s letter follow. An order’s money is worked out from its goods, which a file does not carry, and a file is a snapshot: loaded back, it would put the morning’s numbers over whatever changed since.
Columns
Each column of the file goes to one of the shop’s fields, or is skipped. The
screen guesses: a field’s own name — its key (sku, name_ru,
price_units) or its title as the export writes it (“Name (RU)”) — what
other systems call it (“Product code”, “Артикул”, “VAR Feature 2 [Color]”),
a characteristic by its name. A text goes to one language, or to every one
at once (“All languages”).
A column can carry a formula that changes its value on the way in:
ending($value * 1.2, 90) turns a purchase price into a price ending in 90,
col("Закупка") reads another column. A row the formula cannot work out
keeps that field as it was, and the result says which lines.
Presets
How a file was read — where its columns go, their formulas, the delimiter and the options below — is kept as a preset under the name you give it. The next file with the same columns (four in five are enough) is read the same way without setting anything up.
Check, then import
Check before importing shows what the import would do: how many rows create, update or skip a record, the first hundred of them, and the lines a formula or a missing name stops. Nothing has changed yet. Import then runs in the background: Background tasks shows it, with its counts and notes (“line 12: category created”). Photos given as links are downloaded afterwards by a task of their own.
An upload waits under Unfinished imports until it is imported or deleted; one left alone for a week is deleted with its file.
From the console
The same import without the screen — for a script, or a file that comes every day:
php artisan exim:import prices.csv --dry-run
php artisan exim:import prices.csv
The columns are matched as the screen matches them, by their names or by the
preset saved for them, and the rows are written by the same background task,
listed under Background tasks. A column that goes to no field stops it:
rename the column, save a preset for the file on the screen, or add
--skip-unknown. A formula that cannot be read stops it too.
| Option | |
|---|---|
--dry-run | What Check before importing says; nothing is changed |
--preset="Supplier" | Read the file by this preset (its name or number) |
--no-preset | Match the columns by their names alone |
--skip-new / --create-new | Rows that match nothing: skipped (a price list) / created |
--images=missing | Photo links: empty (only products without photos), missing, replace |
--entity=category | Not products; --fields beside it lists what that takes |
--fields | Every field and the column names it is read from |
--user=you@example.com | The import is this staff member’s, in Background tasks and the audit trail |
--queue | Hand it to the queue worker instead of running it in the console |
Without --user the import is nobody’s, and leaves no audit trail — as
nothing done from the console does. How a file is read (delimiter, encoding,
the XML record) and its formulas come from its preset: set them up once on
the screen, then run the file from the console.
Files and feeds
An export profile is one file: which data, which columns, which format. You can download it from the admin, or give its address to whoever fetches the file — a CRM, a wholesaler, a marketplace.
Data exchange → Export profiles.
A feed for Yandex Market
Make a profile for products in XML, built from Its own template, and pick “Yandex Market (YML)” under Start from a ready template. Delivery terms in it are an example — change them to yours.
Characteristics go into <param> lines: the shop’s characteristics first,
then the product’s own rows (the Individual attributes card). An own row
called like a characteristic the product already has a value of is left
out — a marketplace takes two lines with one name for a mistake.
To send the shop’s characteristics only, put the line inside {{^own}}:
{{#item.params}}{{^own}}<param name="{{ name }}">{{ value }}</param>{{/own}}{{/item.params}}
Which products go in
The Which products card of a product profile. Every field left empty takes everything; together the fields narrow, so a product must pass all of them.
- Statuses — active alone by default, which is what the catalogue lists; tick hidden or disabled to take them too.
- Availability — the shop’s availability statuses (in stock, preorder, out of stock, its own): the product’s is one of the ticked ones.
- Price from / to in the shop’s currency, stock from / to, and the three switches: only what can be ordered now (the availability status allows it and, where it tracks stock, there is some), only with a description (in any language), only with a photo (its own, or by address while the shop allows pictures by address).
- In categories / not in categories — lists of ticks with a search by name, each with or without the subcategories. Nothing ticked on the first means every category.
- Wearing a label — at least one of the ticked ones.
- Characteristics — any number of conditions on the shop’s characteristics: equals, is not, is one of (comma-separated), is none of, contains, does not contain, is greater than, is at least, is less than, is at most, is empty, is set. A value is compared as text in every language and case; the number comparisons read the value’s leading number, so “128 GB” is 128. Is not, is none of, does not contain and is empty also pass a product that has no such characteristic at all. With two or more conditions you choose whether a product must pass all of them or any of them.
- Also take these SKUs — products named by SKU, either as well as the categories and characteristics above (the default) or only those of them that also pass the above. Never take these SKUs wins over everything.
- Stop words — a product mentioning any of the words in a ticked field
(name, short description, description, SEO title and description), in any
language, is left out:
refurbished,display sample.
The card says how many products match right now; the number is counted when the form opens, so it is of the last save.
Keeping the file current
Two ways, on the Updating the file card. Either, both, or neither.
By schedule. Pick from the list, or type a cron expression yourself — five fields: minute, hour, day of the month, month, day of the week:
| Expression | When |
|---|---|
0 3 * * * | every day at 03:00 |
*/30 * * * * | every 30 minutes |
0 9-21 * * 1-5 | every hour from 9:00 to 21:00, Monday to Friday |
0 6,18 * * * | at 06:00 and 18:00 |
The next three builds are shown under the field as you type.
When its data changes. Every five minutes the shop looks whether what the export reads — products, categories, characteristics, prices, photos, stock — has changed since the file was built. Nothing changed, nothing is built. If something did, the file is built again, but not more often than the interval you choose: fifty edits in an hour make two builds, not fifty. A visit to a product page is not a change.
A schedule is worth keeping beside it: some changes leave no trace in the data — a promotion that starts at midnight.
Neither — the address builds a fresh file each time it is asked.
The feed address
With a schedule or the change rule on, the address hands out the last file built, at once, however often it is asked. Files are built in the background: System → Background tasks lists every build and why it ran, and the profile says when the file was built, how many rows it has, its size and how long it took. Only the newest file is kept.
None of it happens unless the server starts the shop’s scheduler every minute — the command is shown on the profile.
The template language
An export profile built from its own template writes the file around the shop’s data: a marketplace feed (Yandex Market, Avito, Google), a CRM’s XML, a price list in any shape. The template is text with tags in it. The language is a subset of Liquid, the one Shopify’s merchants write their themes in, so a feed written for Shopify reads the same here.
Nothing in a template runs as code. A tag can print a value, test it, walk a list, keep a result under a name and run it through the engine’s own filters. It cannot call the shop, read a file, or reach anything but the data it was handed. A template that does too much work on one row is stopped and told so, with the line.
Values
{{ item.sku }}
{{ item.name.ru }}
{{ item.price | price }}
{{ shop.name }}
Inside the rows block a product is item: a column is item.<key>, a text
in one language item.<key>.<language>, a price type’s own price
item.price_type.<CODE>, a characteristic item.feature.<code>. A product
feed also offers item.id, item.url, item.available, item.category_id,
item.price, item.old_price, item.brand, item.pictures (a list of
addresses) and item.params (a list of characteristics with name,
value, code, own). A column the template names is read even when it is
not ticked in the profile.
Outside the rows: profile.name, profile.generated_at; for products
shop.name, shop.url, shop.company, shop.currency, shop.currencies
(id, rate), shop.categories (id, parent_id, name).
An element of a list by its number: item.pictures.0, or by a value:
item.name[shop.locale]. A name that is not there is simply empty.
Every value is escaped for the file’s format, so a quote in a product name
cannot break an XML or JSON file. | raw prints it as it is, | cdata
wraps it in <![CDATA[ … ]]>; in a plain-text file nothing is escaped
unless you ask with | escape.
Filters
A filter changes the value before it is printed; several go in a row, left
to right. An argument comes after a colon; several are separated by commas.
An argument may be a value too: | default: shop.name.
{{ item.description | strip_tags | squish | truncate: 3000 | cdata }}
{{ item.name | remove: item.brand | trim }}
{{ item.weight_g | divide: 1000 }}
| Filter | What it does |
|---|---|
price | a price per unit as a number: 7199000 → 71990 |
money | minor units as an amount: 1250 → 12.50 |
divide: N, multiply: N, plus: N, minus: N, modulo: N | arithmetic (also divided_by, times) |
round: N, ceil, floor, abs, at_least: N, at_most: N | rounding and bounds |
number: N | written with exactly N decimals |
strip_tags (strip_html), squish, strip_newlines | HTML out, spaces made one, line breaks out |
truncate: N, truncatewords: N | at most N characters / words |
lower (downcase), upper (upcase), capitalize | case |
trim (strip), lstrip, rstrip | spaces at the ends |
replace: "a", "b", replace_first: "a", "b", remove: "a" | text replaced (case matters) |
append: "text", prepend: "text" | text added after / before |
slice: from, length | a piece of the text (0 is the first character; -3 the last three) |
split: "," | the text cut into a list |
join: ", ", first, last, size, reverse, sort, sort: "field", uniq, compact | lists |
map: "field", where: "field", "value" | one field of every record; only the matching records |
default: "text" | this text when the value is empty |
date: "d.m.Y" | a date in this form (PHP’s letters) |
url_encode | safe inside a web address |
cdata, raw, escape | how the value is printed |
Arithmetic hands on a number, so | divide: 1000 | plus: 1 adds to 0.171,
not to “0.171”. A number prints with up to four decimals; number: N for
exactly N.
Conditions
{% if item.old_price > item.price %}
<oldprice>{{ item.old_price | price }}</oldprice>
{% endif %}
{% if item.feature.condition contains "как новый" %}
<Condition>Как новый</Condition>
{% elsif item.feature.condition contains "б/у" %}
<Condition>Б/у</Condition>
{% else %}
<Condition>Новое</Condition>
{% endif %}
{% unless item.available %}<Stock>0</Stock>{% endunless %}
A condition is an expression: == (or =), !=, <, >, <=, >=,
contains (a text holds the words, a list holds the value — case does not
matter), and, or, not, brackets, + - * /, & to join text, and the
functions below. Two numbers compare as numbers, anything else as text
without regard to case. Nothing, false, 0, an empty text and an empty list
count as false.
The functions: if(test, then, else), empty(x), default(x, other),
contains(text, part), starts_with, ends_with, len(x), lower,
upper, capitalize, trim, left(text, n), right(text, n),
replace(text, a, b), concat(a, b, …), split(text, ","),
join(list, ", "), first(list), last(list), round(x, n), roundup,
rounddown, ending(x, 90), min, max, abs. The same language is the
language of a column’s formula on import.
Filters are not written inside a condition: keep the result under a name
first ({% assign n = item.set | split: "," | size %}), or use a function
(len(item.pictures) > 0).
Lists
{% for p in item.pictures limit: 10 %}
<picture>{{ p }}</picture>
{% endfor %}
{% for o in options %}<Option>{{ o | trim }}</Option>{% endfor %}
{% for c in shop.categories %}
<category id="{{ c.id }}"{% if c.parent_id %} parentId="{{ c.parent_id }}"{% endif %}>{{ c.name }}</category>
{% endfor %}
Inside the loop forloop.index counts from 1 (forloop.index0 from 0),
forloop.first and forloop.last say where you are, forloop.length how
many there are. limit: N takes the first N, offset: N skips N,
reversed turns the list round; {% break %} leaves the loop,
{% continue %} skips to the next element; {% else %} before endfor
prints when the list is empty. (1..5) counts from 1 to 5.
Names
{% assign model = item.name | remove: item.brand | trim %}
{% assign memory = item.feature.memory | upcase %}
{% if memory == "1 TB" %}{% assign memory = "1024 ГБ" %}{% endif %}
<Model>{{ model }}</Model><MemorySize>{{ memory }}</MemorySize>
{% capture description %}
{{ item.name }} — {{ item.brand }}. {{ item.description | strip_tags | squish }}
{% endcapture %}
<description>{{ description | truncate: 3000 | cdata }}</description>
assign keeps a value under a name, capture keeps everything printed
between its tags. A name lives on from one row to the next, so a counter
across the rows is {% assign n = n | plus: 1 %}.
One of several
{% case item.feature.condition %}
{% when "new" %}<Condition>Новое</Condition>
{% when "used", "worn" %}<Condition>Б/у</Condition>
{% else %}<Condition>?</Condition>
{% endcase %}
A map of “this → that” — the shop’s colours as a marketplace names them —
is the same case, the shop’s names in when, the marketplace’s in
assign; case does not matter in the comparison. Names the map does not
mention keep theirs in the else branch:
{% case item.feature.color %}
{% when "Титановый синий", "Титановый чёрный" %}{% assign color = "Черный" %}
{% when "Синий" %}{% assign color = "Голубой" %}
{% else %}{% assign color = item.feature.color %}
{% endcase %}
<Color>{{ color }}</Color>
The profile’s variables
The card under the template holds values the template reads as
vars.<name>: the delivery cost, whether there is pickup, the name of the
company for this marketplace. Whoever changes a price edits the card, not
the XML.
<delivery-options><option cost="{{ vars.delivery_cost }}" days="{{ vars.delivery_days }}"/></delivery-options>
{% if vars.pickup %}<pickup>true</pickup>{% endif %}
Comments and raw text
{% comment %} … {% endcomment %} is left out of the file; {{! … }} the
same, on one line. {% raw %} … {% endraw %} prints its tags as text.
Whitespace
A tag that stands alone on its line takes the line with it, so a condition
or a loop leaves no blank lines behind. {{-, -}}, {%- and -%} eat
the spaces and line breaks beside them.
The rows
What stands between {% for item in rows %} and {% endfor %} — or
between {{#rows}} and {{/rows}} — is repeated for every row, and the
rows are streamed: a feed of fifty thousand products is written row by row,
never held whole. The block must stand at the top level of the template,
not inside a condition. While streaming, forloop.length and forloop.last
are not known.
Limits
A template may nest tags 32 deep, count a range up to 10 000, take 500 000 steps and print 8 MB for one row. Past any of these it is stopped and the error names the line: a loop inside a loop over big lists is the usual cause. A mistake in a tag refuses the form when the profile is saved; a value that cannot be worked out while the file is built (a division by zero) stops the build with the line.
Templates written before
The tags of the earlier language still work: {{#item.pictures}} … {{ . }} … {{/item.pictures}} once per element, {{#item.old_price}} … {{/…}} only
when there is a value, {{^item.brand}} … {{/…}} only when there is none.
What a template does not do
A template describes one row. What is counted across the whole file — the categories that actually have products in the feed, the first pictures of each — is a value the shop works out and hands to the template, not something the template gathers. If a feed needs such a value and there is none, that is a request for the engine, not a longer template.