Search code examples
phpxmlprestashopprestashop-1.6

Add Combination via Prestashop WEBSERVICE PHP


hope you can guide me(because I dont find any real answer in other existing questions); my code is:

<?php
function make_product_options($data){
   global $webService, $config;

/*try{*/
    $xml = $webService->get(array('url' =>$config["ps_shop"].'api/product_option_values?schema=blank'));

    $product_option_value = $xml->children()->children();

    $product_option_value->id = 1;    
    $product_option_value->id_attribute_group = $data["id_attribute_group"];

    $product_option_value->name->language[0][0] = $data["name"];
    $product_option_value->name->language[0][0]['id'] = 1;


    $opt = array('resource' => 'product_option_values');
    $opt['postXml'] = $xml->asXML();
    $xml = $webService->add($opt); 
    var_dump($xml);
    die();
    $product_option_value = $xml->product_option_values;
  /*} catch (PrestaShopWebserviceException $e){
      return;
    }*/
    return $product->id;
}

but i am getting "400 bad request" the xml sended is:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product_option_value>
    <id>1</id>
    <id_attribute_group>4</id_attribute_group>
    <color/>
    <position/>
    <name><language id="1">Logo Grande</language></name>
</product_option_value>
</prestashop>

Solution

    1. You have to be sure that you are passing a name value for every language in your shop.
    2. If you are adding a combination id value must be empty. If not, could be interpreted as an update.
    3. Active DEBUG MODE en Prestashop shop when webservice is active if you can. This way you will see more validation details in errors.

    Good luck.