Jump to content

PSWebServiceLibrary add product error on PrestaShop 1.6.1.17


Kamad
 Share

Recommended Posts

Hi,
I have an error during add product by webservice
 

My php sample code is:

 

{...}

 

    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
    
    $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/products?schema=blank'));
    $product = $xml->children()->children();
    
    

    $product->id_manufacturer ='1';
    $product->id_supplier ='1';
    $product->id_category_default ='1';
    $product->reference = 'test_abc';
    $product->name = 'test_abc_name';    
    $product->link_rewrite->language[0] = 'test_abc_name2';
    $product->link_rewrite->language[1] = 'test_abc_name2';

 

    $xml = $webService->add(array('resource' => 'products', 'postXml' => $xml->asXML()));
    echo "Successfully added.";

 

{...}

 

 

XML SENT
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product>
<id/>
<id_manufacturer>1</id_manufacturer>
<id_supplier>1</id_supplier>
<id_category_default>1</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>test_abc</reference>
<supplier_reference/>
<location/>
<width/>
<height/>
<depth/>
<weight/>
<quantity_discount/>
<ean13/>
<upc/>
<cache_is_pack/>
<cache_has_attachments/>
<is_virtual/>
<on_sale/>
<online_only/>
<ecotax/>
<minimal_quantity/>
<price/>
<wholesale_price/>
<unity/>
<unit_price_ratio/>
<additional_shipping_cost/>
<customizable/>
<text_fields/>
<uploadable_files/>
<active/>
<redirect_type/>
<id_product_redirected/>
<available_for_order/>
<available_date/>
<condition/>
<show_price/>
<indexed/>
<visibility/>
<advanced_stock_management/>
<date_add/>
<date_upd/>
<pack_stock_type/>
<meta_description><language id="1"/><language id="2"/></meta_description>
<meta_keywords><language id="1"/><language id="2"/></meta_keywords>
<meta_title><language id="1"/><language id="2"/></meta_title>
<link_rewrite><language id="1">test_abc_name2</language><language id="2">test_abc_name2</language></link_rewrite>
<name>test_abc_name</name>
<description><language id="1"/><language id="2"/></description>
<description_short><language id="1"/><language id="2"/></description_short>
<available_now><language id="1"/><language id="2"/></available_now>
<available_later><language id="1"/><language id="2"/></available_later>
<associations>
<categories>
<category>
<id/>
</category>
</categories>
<images>
<image>
<id/>
</image>
</images>
<combinations>
<combination>
<id/>
</combination>
</combinations>
<product_option_values>
<product_option_value>
<id/>
</product_option_value>
</product_option_values>
<product_features>
<product_feature>
<id/>
<id_feature_value/>
</product_feature>
</product_features>
<tags>
<tag>
<id/>
</tag>
</tags>
<stock_availables>
<stock_available>
<id/>
<id_product_attribute/>
</stock_available>
</stock_availables>
<accessories>
<product>
<id/>
</product>
</accessories>
<product_bundle>
<product>
<id/>
<quantity/>
</product>
</product_bundle>
</associations>
</product>
</prestashop>


 

AND this is error:

 

RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[3]]></code>
<message><![CDATA[

 Invalid argument supplied for foreach() (/home/shop/classes/Product.php, line 6054)]]></message>
</error>
</errors>
</prestashop>

 

and this is content from Product.php:

 

    /*
        Create the link rewrite if not exists or invalid on product creation
    */
    public function modifierWsLinkRewrite()
    {
LINE 6054->        foreach ($this->name as $id_lang => $name) {
            if (empty($this->link_rewrite[$id_lang])) {
                $this->link_rewrite[$id_lang] = Tools::link_rewrite($name);
            } elseif (!Validate::isLinkRewrite($this->link_rewrite[$id_lang])) {
                $this->link_rewrite[$id_lang] = Tools::link_rewrite($this->link_rewrite[$id_lang]);
            }
        }

        return true;
    }

 

Big thx for any info and help

Edited by Kamad (see edit history)

Share this post


Link to post
Share on other sites

Hi

 

My Experience with prestashop Web API showed that we cannot use it in production: too many issues have to be solved .

So the best way to import & update  products is to do direct sql calls to database.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

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