PrestaShop-webservice-lib
PrestaShop-webservice-lib copied to clipboard
Fix: PSWebServiceLibrary with sendemail=1 parameter does not work
| Questions | Answers |
|---|---|
| Description? | In case of updating the order_carrier entity via webservice, passing the sendmail parameter the system does not work. |
| Type? | bug fix |
| BC breaks? | no |
| Deprecations? | no |
| Fixed ticket? | Fixes #37249 |
| Sponsor company | @codencode |
| How to test? | see https://github.com/PrestaShop/PrestaShop/issues/37249 |
Hello @Codencode!
This is your first pull request on PrestaShop-webservice-lib repository of the PrestaShop project.
Thank you, and welcome to this Open Source community!
Perhaps a better solution could be to include an additional parameter to be passed, allowing the specification of extra parameters to be "appended" to the URL.
For example:
$opt = [
'resource' => 'order_carriers',
'putXml' => $xml->asXML(),
'id' => $orderCarrierId,
'additionasUrlFields' => [
'sendmail' => 1,
]
];
$webService->edit($opt);
##### method "Edit
public function edit($options)
{
$xml = '';
if ((isset($options['resource'], $options['id']) || isset($options['url'])) && $options['putXml']) {
$url = (isset($options['url']) ? $options['url'] :
$this->url . '/api/' . $options['resource'] . '/' . $options['id']);
$xml = $options['putXml'];
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'];
}
// START new code
if (isset($options['additionasUrlFields'])) {
$url .= '?' . http_build_query($options['additionasUrlFields']);
}
// END new code
} else {
throw new PrestaShopWebserviceException('Bad parameters given');
}
$request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $xml));
$this->checkStatusCode($request);// check the response validity
return $this->parseXML($request['response']);
}