PrestaShopWebservice::add PHP Method

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
    public function add($options)
    {
        $xml = '';
        if (isset($options['resource'], $options['postXml']) || isset($options['url'], $options['postXml'])) {
            $url = isset($options['resource']) ? $this->url . '/api/' . $options['resource'] : $options['url'];
            $xml = $options['postXml'];
            if (isset($options['id_shop'])) {
                $url .= '&id_shop=' . $options['id_shop'];
            }
            if (isset($options['id_group_shop'])) {
                $url .= '&id_group_shop=' . $options['id_group_shop'];
            }
        } else {
            throw new PrestaShopWebserviceException('Bad parameters given');
        }
        $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $xml));
        self::checkStatusCode($request['status_code']);
        return self::parseXML($request['response']);
    }

Usage Example

            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();
            }
        }
    }
All Usage Examples Of PrestaShopWebservice::add