Jump to content

PSWebServiceLibrary add product error on PrestaShop


Recommended Posts

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 version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<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>
<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>


AND this is error:


<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

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


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



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

  • Create New...

Important Information

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