2017-01-29 13 views
2

Я пытаюсь создать новый продукт через веб-сервис Prestashop 1.7.Создайте новый продукт через веб-сервис Prestashop 1.7

Я отправляю следующий XML-код: https://www.myshop.com/api/products. (Я создал данные XML из пустой схемы на https://www.myshop.com/api/products?schema=blank)

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <script></script> 
    <product> 
     <id></id> 
     <id_manufacturer>10</id_manufacturer> 
     <id_supplier></id_supplier> 
     <id_category_default></id_category_default> 
     <new></new> 
     <cache_default_attribute></cache_default_attribute> 
     <id_default_image></id_default_image> 
     <id_default_combination></id_default_combination> 
     <id_tax_rules_group></id_tax_rules_group> 
     <position_in_category></position_in_category> 
     <type></type> 
     <id_shop_default></id_shop_default> 
     <reference></reference> 
     <supplier_reference></supplier_reference> 
     <location></location> 
     <width></width> 
     <height></height> 
     <depth></depth> 
     <weight></weight> 
     <quantity_discount></quantity_discount> 
     <ean13></ean13> 
     <isbn></isbn> 
     <upc></upc> 
     <cache_is_pack></cache_is_pack> 
     <cache_has_attachments></cache_has_attachments> 
     <is_virtual></is_virtual> 
     <state></state> 
     <on_sale></on_sale> 
     <online_only></online_only> 
     <ecotax></ecotax> 
     <minimal_quantity></minimal_quantity> 
     <price>160,37</price> 
     <wholesale_price></wholesale_price> 
     <unity></unity> 
     <unit_price_ratio></unit_price_ratio> 
     <additional_shipping_cost></additional_shipping_cost> 
     <customizable></customizable> 
     <text_fields></text_fields> 
     <uploadable_files></uploadable_files> 
     <active></active> 
     <redirect_type></redirect_type> 
     <id_product_redirected></id_product_redirected> 
     <available_for_order></available_for_order> 
     <available_date></available_date> 
     <show_condition></show_condition> 
     <condition></condition> 
     <show_price></show_price> 
     <indexed></indexed> 
     <visibility></visibility> 
     <advanced_stock_management></advanced_stock_management> 
     <date_add></date_add> 
     <date_upd></date_upd> 
     <pack_stock_type></pack_stock_type> 
     <meta_description> 
      <language id="1">meta_description</language> 
     </meta_description> 
     <meta_keywords> 
      <language id="1">meta_keywords</language> 
     </meta_keywords> 
     <meta_title> 
      <language id="1">meta_title</language> 
     </meta_title> 
     <link_rewrite> 
      <language id="1"></language> 
     </link_rewrite> 
     <name> 
      <language id="1">product name</language> 
     </name> 
     <description> 
      <language id="1">product description</language> 
     </description> 
     <description_short> 
      <language id="1">product short description</language> 
     </description_short> 
     <available_now> 
      <language id="1"></language> 
     </available_now> 
     <available_later> 
      <language id="1"></language> 
     </available_later> 
     <associations> 
      <categories> 
       <category> 
        <id></id> 
       </category> 
      </categories> 
      <images> 
       <image> 
        <id></id> 
       </image> 
      </images> 
      <combinations> 
       <combination> 
        <id></id> 
       </combination> 
      </combinations> 
      <product_option_values> 
       <product_option_value> 
        <id></id> 
       </product_option_value> 
      </product_option_values> 
      <product_features> 
       <product_feature> 
        <id></id> 
        <id_feature_value></id_feature_value> 
       </product_feature> 
      </product_features> 
      <tags> 
       <tag> 
        <id></id> 
       </tag> 
      </tags> 
      <stock_availables> 
       <stock_available> 
        <id></id> 
        <id_product_attribute></id_product_attribute> 
       </stock_available> 
      </stock_availables> 
      <accessories> 
       <product> 
        <id></id> 
       </product> 
      </accessories> 
      <product_bundle> 
       <product> 
        <id></id> 
        <quantity></quantity> 
       </product> 
      </product_bundle> 
     </associations> 
    </product> 
</prestashop> 

Но я получаю следующее сообщение об ошибке:

<?xml version="1.0" encoding="UTF-8"?> 
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
<errors> 
<error> 
<code><![CDATA[41]]></code> 
<message><![CDATA[parameter "price" required]]></message> 
</error> 
</errors> 
</prestashop> 

Как вы можете видеть в публикуемой XML, поле цены имеет значение , Кроме того, значения, содержащиеся в вышеприведенном XML, были достаточными для Prestashop 1.6.

Что я делаю неправильно?

+0

Можете ли вы попробовать с точкой вместо комы для цены? –

+0

@FlorianLemaitre Я уже пробовал это. –

+0

Вы это заработали? Не могли бы вы разместить свой код? – 3zzy

ответ

2

Вам необходимо удалить <script></script> из xml. Я тестировал, он вставляет в таблицы, но не отображается в backoffice. Чтобы показать в backoffice, вам необходимо установить <state>1</state> в xml

+0

Я использовал [Bukimedia.PrestaSharp] (https://github.com/Bukimedia/PrestaSharp) у NuGet, но он не включает поле 'state'. Необходимо создать последний код из GitHub. –