The update workflow is quite similar to the creation workflow, the main difference is that the initial input is not a blank XML but an existing one, so we use the get()
method to get a prefilled XML, and then we can update its fields.
<?php
try {
// creating webservice access
$webService = new PrestaShopWebservice('http://example.com/', 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT', false);
// call to retrieve customer with ID 2
$xml = $webService->get([
'resource' => 'customers',
'id' => 2, // Here we use hard coded value but of course you could get this ID from a request parameter or anywhere else
]);
} catch (PrestaShopWebserviceException $ex) {
// Shows a message related to the error
echo 'Other error: <br />' . $ex->getMessage();
}
Quite similar to the resource creation, except we can update only some fields (since the others are already present) and we use the edit()
method.
Key | Value |
---|---|
resource | customers |
id | resource_id (int) |
putXml | XML content (string) |
<?php
$customerFields = $xml->customer->children();
$customerFields->firstname = 'John';
$customerFields->lastname = 'DOE';
$updatedXml = $webService->edit([
'resource' => 'customers',
'id' => (int) $customerFields->id,
'putXml' => $xml->asXML(),
]);
$customerFields = $updatedXml->customer->children();
echo 'Customer updated with ID ' . $customerFields->id . PHP_EOL;