Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add update (PATCH) #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions PSWebServiceLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,43 @@ public function edit($options)
return $this->parseXML($request['response']);
}

/**
* Update (PATCH) a resource
* <p>Unique parameter must take : <br><br>
* 'resource' => Resource name ,<br>
* 'id' => ID of a resource you want to edit,<br>
* 'patchXml' => Modified XML string of a resource<br><br>
* Examples are given in the tutorial</p>
*
* @param array $options Array representing resource to edit.
*
* @return SimpleXMLElement
* @throws PrestaShopWebserviceException
*/
public function update($options)
{
$xml = '';
if (isset($options['url'])) {
$url = $options['url'];
} elseif ((isset($options['resource'], $options['id']) || isset($options['url'])) && $options['patchXml']) {
$url = (isset($options['url']) ? $options['url'] :
$this->url . '/api/' . $options['resource'] . '/' . $options['id']);
$xml = $options['patchXml'];
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 = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'PATCH', CURLOPT_POSTFIELDS => $xml));
$this->checkStatusCode($request);// check the response validity
return $this->parseXML($request['response']);
}

/**
* Delete (DELETE) a resource.
* Unique parameter must take : <br><br>
Expand Down