Jump to content

Importing product via prestashop's webservice


prince67300

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

Link to comment
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
Link to comment
Share on other sites

  • 5 years later...
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?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...