add() public method

Add (POST) a resource

Unique parameter must take :

'resource' => Resource name
'postXml' => Full XML string to add resource

Examples are given in the tutorial

public add ( array $options ) : SimpleXMLElement
$options array
return SimpleXMLElement status_code, response
            echo 'Bad auth key';
        } else {
            echo 'Other error';
        }
    }
}
if (count($_POST) > 0) {
    // Here we have XML before update, lets update XML
    foreach ($resources as $nodeKey => $node) {
        $resources->{$nodeKey} = $_POST[$nodeKey];
    }
    try {
        $opt = array('resource' => 'customers');
        if ($_GET['Create'] == 'Creating') {
            $opt['postXml'] = $xml->asXML();
            $xml = $webService->add($opt);
            echo "Successfully added.";
        }
    } catch (PrestaShopWebserviceException $ex) {
        // Here we are dealing with errors
        $trace = $ex->getTrace();
        if ($trace[0]['args'][0] == 404) {
            echo 'Bad ID';
        } else {
            if ($trace[0]['args'][0] == 401) {
                echo 'Bad auth key';
            } else {
                echo 'Other error<br />' . $ex->getMessage();
            }
        }
    }
Beispiel #2
0
function add_product_feature_value($feature_id, $value){
        $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
	$opt1 = array('resource' => 'product_feature_values');
        $xml1 = $webService->get(array('url' => PS_SHOP_PATH.'/api/product_feature_values?schema=blank'));
	$resources1 = $xml1->children()->children();
        $resources1->value->language[0]=$value;
        $resources1->value->language[1]=$value;
        $resources1->id_feature=$feature_id;
        $resources1->custom=1;
        $opt1['postXml'] = $xml1->asXML();
        $xml1 = $webService -> add($opt1);
        $result1 = $xml1->children()->children();
        return $result1->{'id'};
}