InSales API - Товары — различия между версиями
Vb (обсуждение | вклад) |
|||
(не показано 29 промежуточных версий 6 участников) | |||
Строка 1: | Строка 1: | ||
=Получение списка товаров= | =Получение списка товаров= | ||
− | Возможные параметры запроса: | + | Возможные параметры запроса для фильтрации: |
* category_id - идентификатор категории на складе | * category_id - идентификатор категории на складе | ||
* collection_id - идентификатор категории на сайте | * collection_id - идентификатор категории на сайте | ||
+ | * deleted - получить удаленные товары | ||
+ | |||
+ | Параметры для получения последних обновленных товаров: | ||
+ | * updated_since - время в UTC, будут отдаваться товары у которых updated_at больше либо равен updated_since | ||
+ | * from_id - ID последнего принятого вами товара. Товары у которых updated_at равен updated_since и ID меньше либо равен from_id не передаются. Это сделано для листания в случае если у большого количества товаров одинаковый updated_at (такое бывает из-за обновления товаров массовыми операциями) | ||
+ | * per_page - количество товаров на странице, за раз можно получить не больше 250 товаров. | ||
+ | |||
+ | В случае если переда параметр updated_since товары упорядочиваются по возрастанию updated_since и возрастанию ID. | ||
+ | |||
+ | Алгоритм работы такой: | ||
+ | * получили пачку товаров, | ||
+ | * если пачка пуста, сохранили updated_since в базу до следующего раза и завершились, | ||
+ | * взяли последний товар из пачки и подставили его updated_at в updated_since, а ID во from_id, | ||
+ | * запросили следующую пачку, | ||
+ | * .... | ||
+ | |||
+ | Параметры для классического перелистывания: | ||
+ | * page - номер страницы, начинается от 1. | ||
+ | * per_page - количество товаров на странице, за раз можно получить не больше 250 товаров. | ||
+ | |||
+ | В этом случае используется сортировка по ID | ||
Запрос: GET /admin/products.xml?category_id=478 | Запрос: GET /admin/products.xml?category_id=478 | ||
Строка 26: | Строка 47: | ||
<meta-keywords nil="true"/> | <meta-keywords nil="true"/> | ||
<meta-description nil="true"/> | <meta-description nil="true"/> | ||
− | < | + | <characteristics type="array"> |
− | < | + | <characteristic> |
− | <id type="integer"> | + | <id type="integer">328</id> |
<position type="integer">1</position> | <position type="integer">1</position> | ||
− | <title> | + | <property-id type="integer">106</property-id> |
− | </ | + | <title>в линейку</title> |
− | </option-names> | + | <permalink>rulled</permalink> |
+ | </characteristic> | ||
+ | </characteristics> | ||
+ | <properties type="array"> | ||
+ | <property> | ||
+ | <id type="integer">106</id> | ||
+ | <position type="integer">1</position> | ||
+ | <title>Бумага</title> | ||
+ | <permalink>bumaga</permalink> | ||
+ | </property> | ||
+ | </properties> | ||
+ | <option-names type="array"/> | ||
<images type="array"> | <images type="array"> | ||
<image> | <image> | ||
Строка 53: | Строка 85: | ||
<sku>QP021MVEN-r</sku> | <sku>QP021MVEN-r</sku> | ||
<updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> | <updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> | ||
− | <title | + | <title nil="true"/> |
− | <option-values type="array" | + | <option-values type="array"/> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</variant> | </variant> | ||
</variants> | </variants> | ||
Строка 78: | Строка 103: | ||
<meta-keywords nil="true"/> | <meta-keywords nil="true"/> | ||
<meta-description nil="true"/> | <meta-description nil="true"/> | ||
− | < | + | <characteristics type="array"> |
− | < | + | <characteristic> |
− | <id type="integer"> | + | <id type="integer">328</id> |
+ | <position type="integer">1</position> | ||
+ | <property-id type="integer">106</property-id> | ||
+ | <title>в линейку</title> | ||
+ | <permalink>rulled</permalink> | ||
+ | </characteristic> | ||
+ | </characteristics> | ||
+ | <properties type="array"> | ||
+ | <property> | ||
+ | <id type="integer">106</id> | ||
<position type="integer">1</position> | <position type="integer">1</position> | ||
− | <title> | + | <title>Бумага</title> |
− | </ | + | <permalink>bumaga</permalink> |
− | </option-names> | + | </property> |
+ | </properties> | ||
+ | <option-names type="array"/> | ||
<images type="array"> | <images type="array"> | ||
<image> | <image> | ||
Строка 105: | Строка 141: | ||
<sku>QP023MVEN-o</sku> | <sku>QP023MVEN-o</sku> | ||
<updated-at type="timestamp">2010-07-16 13:20:05 +0400</updated-at> | <updated-at type="timestamp">2010-07-16 13:20:05 +0400</updated-at> | ||
− | <title | + | <title nil="true"/> |
− | <option-values type="array" | + | <option-values type="array"/> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</variant> | </variant> | ||
</variants> | </variants> | ||
Строка 141: | Строка 170: | ||
<meta-keywords nil="true"/> | <meta-keywords nil="true"/> | ||
<meta-description nil="true"/> | <meta-description nil="true"/> | ||
− | < | + | <characteristics type="array"> |
− | < | + | <characteristic> |
− | <id type="integer"> | + | <id type="integer">328</id> |
+ | <position type="integer">1</position> | ||
+ | <property-id type="integer">106</property-id> | ||
+ | <title>в линейку</title> | ||
+ | <permalink>rulled</permalink> | ||
+ | </characteristic> | ||
+ | </characteristics> | ||
+ | <properties type="array"> | ||
+ | <property> | ||
+ | <id type="integer">106</id> | ||
<position type="integer">1</position> | <position type="integer">1</position> | ||
− | <title> | + | <title>Бумага</title> |
− | </ | + | <permalink>bumaga</permalink> |
− | </option-names> | + | </property> |
+ | </properties> | ||
+ | <option-names type="array"/> | ||
<images type="array"> | <images type="array"> | ||
<image> | <image> | ||
Строка 168: | Строка 208: | ||
<sku>QP021MVEN-r</sku> | <sku>QP021MVEN-r</sku> | ||
<updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> | <updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> | ||
− | <title | + | <title nil="true"/> |
− | <option-values type="array" | + | <option-values type="array"/> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</variant> | </variant> | ||
</variants> | </variants> | ||
Строка 184: | Строка 217: | ||
=Добавление товара= | =Добавление товара= | ||
− | ==Добавление товара с | + | ==Добавление товара с параметрами== |
Запрос: POST /admin/products.xml | Запрос: POST /admin/products.xml | ||
Строка 194: | Строка 227: | ||
<description>&lt;p&gt;&lt;span style=&quot;font-family: 'Times New Roman'; font-size: 16px;&quot;&gt; &lt;/span&gt;&lt;/p&gt;</description> | <description>&lt;p&gt;&lt;span style=&quot;font-family: 'Times New Roman'; font-size: 16px;&quot;&gt; &lt;/span&gt;&lt;/p&gt;</description> | ||
<short-description>Алая записная книжка "Ван Гог" в линейку</short-description> | <short-description>Алая записная книжка "Ван Гог" в линейку</short-description> | ||
− | <variants type="array"> | + | <properties-attributes type="array"> |
− | < | + | <properties-attribute> |
+ | <title>Бумага</title> | ||
+ | <value>в линейку</value> | ||
+ | </properties-attribute> | ||
+ | </properties-attributes> | ||
+ | <variants-attributes type="array"> | ||
+ | <variants-attribute> | ||
<sku>QP021MVEN-r</sku> | <sku>QP021MVEN-r</sku> | ||
<quantity type="integer" nil="true"/> | <quantity type="integer" nil="true"/> | ||
Строка 201: | Строка 240: | ||
<cost-price type="decimal">487.0</cost-price> | <cost-price type="decimal">487.0</cost-price> | ||
<old-price type="decimal" nil="true"/> | <old-price type="decimal" nil="true"/> | ||
− | </ | + | </variants-attribute> |
− | </variants> | + | </variants-attributes> |
</product> | </product> | ||
</pre> | </pre> | ||
Строка 223: | Строка 262: | ||
<meta-keywords nil="true"/> | <meta-keywords nil="true"/> | ||
<meta-description nil="true"/> | <meta-description nil="true"/> | ||
− | < | + | <characteristics type="array"> |
− | < | + | <characteristic> |
− | <id type="integer"> | + | <id type="integer">328</id> |
+ | <position type="integer">1</position> | ||
+ | <property-id type="integer">106</property-id> | ||
+ | <title>в линейку</title> | ||
+ | <permalink>rulled</permalink> | ||
+ | </characteristic> | ||
+ | </characteristics> | ||
+ | <properties type="array"> | ||
+ | <property> | ||
+ | <id type="integer">106</id> | ||
<position type="integer">1</position> | <position type="integer">1</position> | ||
− | <title> | + | <title>Бумага</title> |
− | </ | + | <permalink>bumaga</permalink> |
− | </option-names> | + | </property> |
+ | </properties> | ||
+ | <option-names type="array"/> | ||
<images type="array" /> | <images type="array" /> | ||
<variants type="array"> | <variants type="array"> | ||
Строка 242: | Строка 292: | ||
<sku>QP021MVEN-r</sku> | <sku>QP021MVEN-r</sku> | ||
<updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> | <updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> | ||
− | <title | + | <title nil="true"/> |
− | <option-values type="array" | + | <option-values type="array"/> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</variant> | </variant> | ||
</variants> | </variants> | ||
Строка 256: | Строка 299: | ||
</pre> | </pre> | ||
− | ==Добавление товара | + | ==Добавление товара со свойствами== |
Запрос: POST /admin/products.xml | Запрос: POST /admin/products.xml | ||
Строка 266: | Строка 309: | ||
<title>Модная майка</title> | <title>Модная майка</title> | ||
<options type="array"> | <options type="array"> | ||
− | <option | + | <option> |
<title>Размер</title> | <title>Размер</title> | ||
<value>XL</value> | <value>XL</value> | ||
− | </option | + | </option> |
− | <option | + | <option> |
<title>Цвет</title> | <title>Цвет</title> | ||
<value>белый</value> | <value>белый</value> | ||
− | </option | + | </option> |
− | </ | + | </options> |
− | <variants type="array"> | + | <variants-attributes type="array"> |
− | < | + | <variants-attribute> |
<cost-price type="decimal">487.0</cost-price> | <cost-price type="decimal">487.0</cost-price> | ||
<old-price type="decimal">1000</old-price> | <old-price type="decimal">1000</old-price> | ||
<price type="decimal">740.0</price> | <price type="decimal">740.0</price> | ||
<quantity type="integer">10</quantity> | <quantity type="integer">10</quantity> | ||
− | </ | + | </variants-attribute> |
− | </variants> | + | </variants-attributes> |
</product> | </product> | ||
</pre> | </pre> | ||
Строка 303: | Строка 346: | ||
<meta-keywords nil="true"/> | <meta-keywords nil="true"/> | ||
<meta-description nil="true"/> | <meta-description nil="true"/> | ||
+ | <characteristics type="array"/> | ||
+ | <properties type="array"/> | ||
<option-names type="array"> | <option-names type="array"> | ||
<option-name> | <option-name> | ||
Строка 346: | Строка 391: | ||
</product> | </product> | ||
</pre> | </pre> | ||
+ | |||
+ | ==Добавление товара с несколькими модификациями== | ||
+ | |||
+ | Добавление товара с несколькими модификациями делается в два запроса. Первым запросом мы [[#Добавление товара со свойствами|создаем товар с необходимыми свойствами и одной модификацией]]. Вторым запросом мы добавляем оставшиеся модификации. | ||
+ | |||
+ | Запрос: PUT /admin/products/#{id}.xml | ||
+ | <pre> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <product> | ||
+ | <category-id type="integer">478</category-id> | ||
+ | <variants-attributes type="array"> | ||
+ | <variants-attribute> | ||
+ | <cost-price type="decimal">487.0</cost-price> | ||
+ | <old-price type="decimal">1000</old-price> | ||
+ | <price type="decimal">740.0</price> | ||
+ | <quantity type="integer">10</quantity> | ||
+ | <options type="array"> | ||
+ | <option> | ||
+ | <option-name-id type="integer">202088</option-name-id> | ||
+ | <value>value 1</value> | ||
+ | </option> | ||
+ | </options> | ||
+ | </variants-attribute> | ||
+ | <variants-attribute> | ||
+ | <cost-price type="decimal">600.0</cost-price> | ||
+ | <old-price type="decimal">1100</old-price> | ||
+ | <price type="decimal">800.0</price> | ||
+ | <quantity type="integer">2</quantity> | ||
+ | <options> | ||
+ | <option> | ||
+ | <option-name-id type="integer">202088</option-name-id> | ||
+ | <value>value 2</value> | ||
+ | </option> | ||
+ | </options> | ||
+ | </variants-attribute> | ||
+ | </variants-attributes> | ||
+ | </product> | ||
+ | </pre> | ||
+ | |||
+ | ==Добавление товару со свойствами еще одного свойства == | ||
+ | |||
+ | Для уже существующих свойств необходимо передать их id, чтобы система не пробовала их пересоздать, допустим мы хотим добавить свойство Цвет и всем текущим модификациям (variants) проставить значение Красный : | ||
+ | |||
+ | Запрос: PUT /admin/products/#{id}.xml | ||
+ | <pre> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <product> | ||
+ | <options type="array"> | ||
+ | <option> | ||
+ | <option-name-id type="integer">101435</option-name-id> | ||
+ | </option> | ||
+ | <option> | ||
+ | <option-name-id type="integer">118010</option-name-id> | ||
+ | </option> | ||
+ | <option> | ||
+ | <title>Цвет</title> | ||
+ | <value>Красный</value> | ||
+ | </option> | ||
+ | </options> | ||
+ | </product> | ||
+ | </pre> | ||
+ | |||
=Редактирование товара= | =Редактирование товара= | ||
+ | |||
+ | ==Изменение наименования товара== | ||
Запрос: PUT /admin/products/#{id}.xml | Запрос: PUT /admin/products/#{id}.xml | ||
Строка 361: | Строка 470: | ||
<pre> | <pre> | ||
HTTP/1.1 200 OK | HTTP/1.1 200 OK | ||
+ | </pre> | ||
+ | |||
+ | ==Изменение параметров товара== | ||
+ | |||
+ | '''Важный момент: передавать надо все параметры, если ранее установленный параметр не будет передан в запросе, то он будет удален.''' | ||
+ | |||
+ | Запрос: PUT /admin/products/#{id}.xml | ||
+ | <pre> | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<product> | <product> | ||
− | |||
− | |||
<id type="integer">41658</id> | <id type="integer">41658</id> | ||
− | < | + | <properties-attributes type="array"> |
− | + | <properties-attribute> | |
− | + | <title>Бумага</title> | |
− | + | <value>в линейку</value> | |
− | + | </properties-attribute> | |
− | + | </properties-attributes> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | <title> | ||
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | </ | ||
</product> | </product> | ||
+ | </pre> | ||
+ | |||
+ | Ответ: | ||
+ | <pre> | ||
+ | HTTP/1.1 200 OK | ||
</pre> | </pre> | ||
Текущая версия на 07:58, 4 апреля 2018
Содержание
Получение списка товаров
Возможные параметры запроса для фильтрации:
- category_id - идентификатор категории на складе
- collection_id - идентификатор категории на сайте
- deleted - получить удаленные товары
Параметры для получения последних обновленных товаров:
- updated_since - время в UTC, будут отдаваться товары у которых updated_at больше либо равен updated_since
- from_id - ID последнего принятого вами товара. Товары у которых updated_at равен updated_since и ID меньше либо равен from_id не передаются. Это сделано для листания в случае если у большого количества товаров одинаковый updated_at (такое бывает из-за обновления товаров массовыми операциями)
- per_page - количество товаров на странице, за раз можно получить не больше 250 товаров.
В случае если переда параметр updated_since товары упорядочиваются по возрастанию updated_since и возрастанию ID.
Алгоритм работы такой:
- получили пачку товаров,
- если пачка пуста, сохранили updated_since в базу до следующего раза и завершились,
- взяли последний товар из пачки и подставили его updated_at в updated_since, а ID во from_id,
- запросили следующую пачку,
- ....
Параметры для классического перелистывания:
- page - номер страницы, начинается от 1.
- per_page - количество товаров на странице, за раз можно получить не больше 250 товаров.
В этом случае используется сортировка по ID
Запрос: GET /admin/products.xml?category_id=478
Ответ:
HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <products type="array"> <product> <category-id type="integer">478</category-id> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">41658</id> <is-hidden type="boolean">false</is-hidden> <updated-at type="timestamp">2010-07-14 13:40:01 +0400</updated-at> <title>Van Gogh Ruled Peach Notebook</title> <description><p><span style="font-family: 'Times New Roman'; font-size: 16px;"> </span></p></description> <short-description>Алая записная книжка "Ван Гог" в линейку</short-description> <permalink>Van-Gogh-Ruled-Rose-Notebook</permalink> <html-title nil="true"/> <meta-keywords nil="true"/> <meta-description nil="true"/> <characteristics type="array"> <characteristic> <id type="integer">328</id> <position type="integer">1</position> <property-id type="integer">106</property-id> <title>в линейку</title> <permalink>rulled</permalink> </characteristic> </characteristics> <properties type="array"> <property> <id type="integer">106</id> <position type="integer">1</position> <title>Бумага</title> <permalink>bumaga</permalink> </property> </properties> <option-names type="array"/> <images type="array"> <image> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">24690</id> <position type="integer">1</position> <url>http://static.insales.ru/images/products/24690/thumb/vangogh-red.jpg</url> <title nil="true"/> </image> </images> <variants type="array"> <variant> <cost-price type="decimal">487.0</cost-price> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">48136</id> <old-price type="decimal" nil="true"/> <price type="decimal">740.0</price> <product-id type="integer">41658</product-id> <quantity type="integer" nil="true"/> <sku>QP021MVEN-r</sku> <updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> <title nil="true"/> <option-values type="array"/> </variant> </variants> </product> <product> <category-id type="integer">478</category-id> <created-at type="timestamp">2009-04-10 00:00:05 +0400</created-at> <id type="integer">15757</id> <is-hidden type="boolean">false</is-hidden> <updated-at type="timestamp">2009-12-08 14:58:34 +0300</updated-at> <title>Van Gogh Sketchbook Peach</title> <description nil="true" /> <short-description>Персиковая записная книжка "Ван Гог" для рисунков</short-description> <permalink>Van-Gogh-Sketchbook-Peach</permalink> <html-title nil="true"/> <meta-keywords nil="true"/> <meta-description nil="true"/> <characteristics type="array"> <characteristic> <id type="integer">328</id> <position type="integer">1</position> <property-id type="integer">106</property-id> <title>в линейку</title> <permalink>rulled</permalink> </characteristic> </characteristics> <properties type="array"> <property> <id type="integer">106</id> <position type="integer">1</position> <title>Бумага</title> <permalink>bumaga</permalink> </property> </properties> <option-names type="array"/> <images type="array"> <image> <created-at type="timestamp">2009-04-10 00:00:05 +0400</created-at> <id type="integer">13886</id> <position type="integer">1</position> <url>http://static.insales.ru/images/products/13886/thumb/vangogh-orange.jpg</url> <title nil="true"/> </image> </images> <variants type="array"> <variant> <cost-price type="decimal">487.0</cost-price> <created-at type="timestamp">2009-04-10 00:00:05 +0400</created-at> <id type="integer">16638</id> <old-price type="decimal" nil="true"/> <price type="decimal">740.0</price> <product-id type="integer">15757</product-id> <quantity type="integer">0</quantity> <sku>QP023MVEN-o</sku> <updated-at type="timestamp">2010-07-16 13:20:05 +0400</updated-at> <title nil="true"/> <option-values type="array"/> </variant> </variants> </product> </products>
Получение информации о товаре
Запрос: GET /admin/products/#{id}.xml
Ответ:
HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <product> <category-id type="integer">478</category-id> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">41658</id> <is-hidden type="boolean">false</is-hidden> <updated-at type="timestamp">2010-07-14 13:40:01 +0400</updated-at> <title>Van Gogh Ruled Peach Notebook</title> <description><p><span style="font-family: 'Times New Roman'; font-size: 16px;"> </span></p></description> <short-description>Алая записная книжка "Ван Гог" в линейку</short-description> <permalink>Van-Gogh-Ruled-Rose-Notebook</permalink> <html-title nil="true"/> <meta-keywords nil="true"/> <meta-description nil="true"/> <characteristics type="array"> <characteristic> <id type="integer">328</id> <position type="integer">1</position> <property-id type="integer">106</property-id> <title>в линейку</title> <permalink>rulled</permalink> </characteristic> </characteristics> <properties type="array"> <property> <id type="integer">106</id> <position type="integer">1</position> <title>Бумага</title> <permalink>bumaga</permalink> </property> </properties> <option-names type="array"/> <images type="array"> <image> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">24690</id> <position type="integer">1</position> <url>http://static.insales.ru/images/products/24690/thumb/vangogh-red.jpg</url> <title nil="true"/> </image> </images> <variants type="array"> <variant> <cost-price type="decimal">487.0</cost-price> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">48136</id> <old-price type="decimal" nil="true"/> <price type="decimal">740.0</price> <product-id type="integer">41658</product-id> <quantity type="integer" nil="true"/> <sku>QP021MVEN-r</sku> <updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> <title nil="true"/> <option-values type="array"/> </variant> </variants> </product>
Добавление товара
Добавление товара с параметрами
Запрос: POST /admin/products.xml
<?xml version="1.0" encoding="UTF-8"?> <product> <category-id type="integer">478</category-id> <title>Van Gogh Ruled Peach Notebook</title> <description><p><span style="font-family: 'Times New Roman'; font-size: 16px;"> </span></p></description> <short-description>Алая записная книжка "Ван Гог" в линейку</short-description> <properties-attributes type="array"> <properties-attribute> <title>Бумага</title> <value>в линейку</value> </properties-attribute> </properties-attributes> <variants-attributes type="array"> <variants-attribute> <sku>QP021MVEN-r</sku> <quantity type="integer" nil="true"/> <price type="decimal">740.0</price> <cost-price type="decimal">487.0</cost-price> <old-price type="decimal" nil="true"/> </variants-attribute> </variants-attributes> </product>
Ответ:
HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <product> <category-id type="integer">478</category-id> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">41658</id> <is-hidden type="boolean">false</is-hidden> <updated-at type="timestamp">2010-07-14 13:40:01 +0400</updated-at> <title>Van Gogh Ruled Peach Notebook</title> <description><p><span style="font-family: 'Times New Roman'; font-size: 16px;"> </span></p></description> <short-description>Алая записная книжка "Ван Гог" в линейку</short-description> <permalink>Van-Gogh-Ruled-Rose-Notebook</permalink> <html-title nil="true"/> <meta-keywords nil="true"/> <meta-description nil="true"/> <characteristics type="array"> <characteristic> <id type="integer">328</id> <position type="integer">1</position> <property-id type="integer">106</property-id> <title>в линейку</title> <permalink>rulled</permalink> </characteristic> </characteristics> <properties type="array"> <property> <id type="integer">106</id> <position type="integer">1</position> <title>Бумага</title> <permalink>bumaga</permalink> </property> </properties> <option-names type="array"/> <images type="array" /> <variants type="array"> <variant> <cost-price type="decimal">487.0</cost-price> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <id type="integer">48136</id> <old-price type="decimal" nil="true"/> <price type="decimal">740.0</price> <product-id type="integer">41658</product-id> <quantity type="integer" nil="true"/> <sku>QP021MVEN-r</sku> <updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> <title nil="true"/> <option-values type="array"/> </variant> </variants> </product>
Добавление товара со свойствами
Запрос: POST /admin/products.xml
<?xml version="1.0" encoding="UTF-8"?> <product> <category-id type="integer">478</category-id> <is-hidden type="boolean">false</is-hidden> <title>Модная майка</title> <options type="array"> <option> <title>Размер</title> <value>XL</value> </option> <option> <title>Цвет</title> <value>белый</value> </option> </options> <variants-attributes type="array"> <variants-attribute> <cost-price type="decimal">487.0</cost-price> <old-price type="decimal">1000</old-price> <price type="decimal">740.0</price> <quantity type="integer">10</quantity> </variants-attribute> </variants-attributes> </product>
Ответ:
HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <product> <id type="integer">41658</id> <category-id type="integer">478</category-id> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <is-hidden type="boolean">false</is-hidden> <updated-at type="timestamp">2010-07-14 13:40:01 +0400</updated-at> <title>Майка</title> <description nil="true"> <short-description nil="true"> <permalink>Majka</permalink> <html-title nil="true"/> <meta-keywords nil="true"/> <meta-description nil="true"/> <characteristics type="array"/> <properties type="array"/> <option-names type="array"> <option-name> <id type="integer">1171</id> <position type="integer">1</position> <title>Размер</title> </option-name> <option-name> <id type="integer">1172</id> <position type="integer">2</position> <title>Цвет</title> </option-name> </option-names> <images type="array" /> <variants type="array"> <variant> <id type="integer">48136</id> <product-id type="integer">41658</product-id> <cost-price type="decimal">487.0</cost-price> <old-price type="decimal">1000</old-price> <price type="decimal">740.0</price> <quantity type="integer">10</quantity> <sku nil="true" /> <title>XL/белый</title> <created-at type="timestamp">2009-06-04 14:22:34 +0400</created-at> <updated-at type="timestamp">2010-07-16 13:20:04 +0400</updated-at> <option-values type="array"> <option-value> <id type="integer">5649</id> <option-name-id type="integer">1171</option-name-id> <position type="integer">1</position> <value>XL</value> </option-value> <option-value> <id type="integer">5650</id> <option-name-id type="integer">1172</option-name-id> <position type="integer">1</position> <value>белый</value> </option-value> </option-values> </variant> </variants> </product>
Добавление товара с несколькими модификациями
Добавление товара с несколькими модификациями делается в два запроса. Первым запросом мы создаем товар с необходимыми свойствами и одной модификацией. Вторым запросом мы добавляем оставшиеся модификации.
Запрос: PUT /admin/products/#{id}.xml
<?xml version="1.0" encoding="UTF-8"?> <product> <category-id type="integer">478</category-id> <variants-attributes type="array"> <variants-attribute> <cost-price type="decimal">487.0</cost-price> <old-price type="decimal">1000</old-price> <price type="decimal">740.0</price> <quantity type="integer">10</quantity> <options type="array"> <option> <option-name-id type="integer">202088</option-name-id> <value>value 1</value> </option> </options> </variants-attribute> <variants-attribute> <cost-price type="decimal">600.0</cost-price> <old-price type="decimal">1100</old-price> <price type="decimal">800.0</price> <quantity type="integer">2</quantity> <options> <option> <option-name-id type="integer">202088</option-name-id> <value>value 2</value> </option> </options> </variants-attribute> </variants-attributes> </product>
Добавление товару со свойствами еще одного свойства
Для уже существующих свойств необходимо передать их id, чтобы система не пробовала их пересоздать, допустим мы хотим добавить свойство Цвет и всем текущим модификациям (variants) проставить значение Красный :
Запрос: PUT /admin/products/#{id}.xml
<?xml version="1.0" encoding="UTF-8"?> <product> <options type="array"> <option> <option-name-id type="integer">101435</option-name-id> </option> <option> <option-name-id type="integer">118010</option-name-id> </option> <option> <title>Цвет</title> <value>Красный</value> </option> </options> </product>
Редактирование товара
Изменение наименования товара
Запрос: PUT /admin/products/#{id}.xml
<?xml version="1.0" encoding="UTF-8"?> <product> <id type="integer">41658</id> <title>Van Gogh Ruled Peach Notebook</title> </product>
Ответ:
HTTP/1.1 200 OK
Изменение параметров товара
Важный момент: передавать надо все параметры, если ранее установленный параметр не будет передан в запросе, то он будет удален.
Запрос: PUT /admin/products/#{id}.xml
<?xml version="1.0" encoding="UTF-8"?> <product> <id type="integer">41658</id> <properties-attributes type="array"> <properties-attribute> <title>Бумага</title> <value>в линейку</value> </properties-attribute> </properties-attributes> </product>
Ответ:
HTTP/1.1 200 OK
Удаление товара
Запрос: DELETE /admin/products/#{id}.xml
Ответ:
HTTP/1.1 200 OK