Jump to content
prince67300

Importing product via prestashop's webservice

Recommended Posts

Hi all !

 

I'm trying to import some products to my prestashop using REST webservice. The problem is when I try to add a product to an empty category I created using webservice or using PS web interface, I get the following response:

<error>
<code><![CDATA[135]]></code>
<message><![CDATA[You cannot set a position greater than the total number of products in the category, minus 1 (position numbering starts at 0).]]></message>
</error>
It occurs with the first product. If I add it via web interface and I add the others using webservice, it works.

 

XML:

 

 

Adding product request:

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
  <product>
	  <id/>
	  <id_manufacturer/>
	  <id_supplier/>
	  <id_category_default><![CDATA[1365]]></id_category_default>
	  <new/>
	  <cache_default_attribute/>
	  <id_default_image/>
	  <id_default_combination/>
	  <id_tax_rules_group/>
	  <position_in_category/>
	  <type/>
	  <id_shop_default/>
	  <reference><![CDATA[0]]></reference>
	  <supplier_reference/>
	  <location/>
	  <width/>
	  <height/>
	  <depth/>
	  <weight><![CDATA[1.18]]></weight>
	  <quantity_discount/>
	  <ean13><![CDATA[1]]></ean13>
	  <upc/>
	  <cache_is_pack/>
	  <cache_has_attachments/>
	  <is_virtual/>
	  <on_sale/>
	  <online_only/>
	  <ecotax/>
	  <minimal_quantity/>
	  <price><![CDATA[599]]></price>
	  <wholesale_price/>
	  <unity/>
	  <unit_price_ratio/>
	  <additional_shipping_cost/>
	  <customizable/>
	  <text_fields/>
	  <uploadable_files/>
	  <active><![CDATA[1]]></active>
	  <redirect_type/>
	  <id_product_redirected/>
	  <available_for_order/>
	  <available_date/>
	  <condition/>
	  <show_price/>
	  <indexed/>
	  <visibility/>
	  <advanced_stock_management/>
	  <date_add/>
	  <date_upd/>
	  <meta_description>
      <language id="1"/>
    </meta_description>
	  <meta_keywords>
      <language id="1"/>
    </meta_keywords>
	  <meta_title>
      <language id="1"/>
    </meta_title>
	  <link_rewrite>
      <language id="1"/>
    </link_rewrite>
	  <name>
      <language id="1"><![CDATA[Product]]></language>
    </name>
	  <description>
      <language id="1"><![CDATA[<p></p>]]></language>
    </description>
	  <description_short>
      <language id="1"><![CDATA[<p></p>]]></language>
    </description_short>
	  <available_now>
      <language id="1"/>
    </available_now>
	  <available_later>
      <language id="1"/>
    </available_later>
    <associations>
      <categories>
	      <categories>
	        <id/>
	</categories>
</categories>
      <images>
	      <images>
	        <id/>
	</images>
</images>
      <combinations>
	      <combinations>
	        <id/>
	</combinations>
</combinations>
      <product_option_values>
	      <product_option_values>
	        <id/>
	</product_option_values>
</product_option_values>
      <product_features>
	      <product_features>
	        <id/>
	        <custom/>
	        <id_feature_value/>
	</product_features>
</product_features>
      <tags>
	      <tags>
	        <id/>
	</tags>
</tags>
      <stock_availables>
	      <stock_availables>
	        <id/>
	        <id_product_attribute/>
	</stock_availables>
</stock_availables>
      <accessories>
	      <products>
	        <id/>
	</products>
</accessories>
      <product_bundle>
	      <products>
	        <id/>
	        <quantity/>
	</products>
</product_bundle>
</associations>
 </product>
</prestashop>
Empty category:

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<script id="tinyhippos-injected"/>
<category>
<id>
<![CDATA[ 1365 ]]>
</id>
<id_parent xlink:href="http://terra.ccanim.com/api/categories/2">
<![CDATA[ 2 ]]>
</id_parent>
<level_depth>
<![CDATA[ 2 ]]>
</level_depth>
<nb_products_recursive not_filterable="true">
<![CDATA[ -1 ]]>
</nb_products_recursive>
<active>
<![CDATA[ 1 ]]>
</active>
<id_shop_default>
<![CDATA[ 1 ]]>
</id_shop_default>
<is_root_category>
<![CDATA[ 0 ]]>
</is_root_category>
<position>
<![CDATA[ 2 ]]>
</position>
<date_add>
<![CDATA[ 2014-10-07 16:29:47 ]]>
</date_add>
<date_upd>
<![CDATA[ 2014-10-07 16:29:47 ]]>
</date_upd>
<name>
<language id="1" xlink:href="http://terra.ccanim.com/api/languages/1">
<![CDATA[ LAN ]]>
</language>
</name>
<link_rewrite>
<language id="1" xlink:href="http://terra.ccanim.com/api/languages/1">
<![CDATA[ lan ]]>
</language>
</link_rewrite>
<description>
<language id="1" xlink:href="http://terra.ccanim.com/api/languages/1">
<![CDATA[ ]]>
</language>
</description>
<meta_title>
<language id="1" xlink:href="http://terra.ccanim.com/api/languages/1">
<![CDATA[ ]]>
</language>
</meta_title>
<meta_description>
<language id="1" xlink:href="http://terra.ccanim.com/api/languages/1">
<![CDATA[ ]]>
</language>
</meta_description>
<meta_keywords>
<language id="1" xlink:href="http://terra.ccanim.com/api/languages/1">
<![CDATA[ ]]>
</language>
</meta_keywords>
<associations>
<categories node_type="categories"/>
<products node_type="products"/>
</associations>
</category>
</prestashop>

 

 

I've already read this topic http://www.prestashop.com/forums/topic/347750-solvedcant-add-product-to-empty-category-using-webservice/ but the solution is not really a solution so does anyone have an idea about this issue ?

 

Thanks for your answers

Share this post


Link to post
Share on other sites

I've already read this topic but the problem is not how it works. The problem is this error thrown by the server because when I try to create the product in a not-empty category, it works.

Edited by prince67300 (see edit history)

Share this post


Link to post
Share on other sites

Hello, 

 

It look like a bug in classes/Product.php at line 4872:

 

"if ($position + 1 > count($result)) "

When category is empty then only logical value for position is -1 which is not possible ...

 

Just comment line 4872 and 4873 in that file and it will work.

 

Matus

  • Like 1

Share this post


Link to post
Share on other sites

Hi,

I am looking for a solution to import product from csv using webservice, 

Do you find a solution ?

Thanks for any help

 

Share this post


Link to post
Share on other sites
On 10/21/2014 at 5:14 PM, bxmatus said:

Hello, 

 

It look like a bug in classes/Product.php at line 4872:

 

"if ($position + 1 > count($result)) "

When category is empty then only logical value for position is -1 which is not possible ...

 

Just comment line 4872 and 4873 in that file and it will work.

 

Matus

Hello

Shouldn't this be reported as a bug so that PrestaShop people could globally correct it?

Share this post


Link to post
Share on other sites

@camillo777 The topic on which you are posting is from 2014 ! Which Prestashop version are you using ? Webservice Api had several changes after 2014.

Share this post


Link to post
Share on other sites
2 minutes ago, selectshop.at said:

@camillo777 The topic on which you are posting is from 2014 ! Which Prestashop version are you using ? Webservice Api had several changes after 2014.

Oh, I did not have the forums sorted by date, sorry.

Share this post


Link to post
Share on other sites
2 minutes ago, camillo777 said:

Oh, I did not have the forums sorted by date, sorry.

There is no possibility to sort this by date in this case. You should simply read first topic. This here is from 2014.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More