Reputation: 51
Hi guys like the title says I don't know how to delete images. I can add and update them but I don't find the way to delete them.
This is the code I used to update and add an image:
$idProduct = 54;
$idImage = 26;
//$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProducto . "/"; //Uncomment this line to add an image
$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProduct . "/".$idImage."?ps_method=PUT";
$image_path = 'C:\\camisa2.jpg';
$key = 'XXXXXXXXXXXXXXXXXXX'; //Prestashop key
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path.';type=image/jpg'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo "<h3>Image Updated</h3>";
Any help will be appreciated.
Greetings
Upvotes: 0
Views: 2819
Reputation: 21
Just try this:
$url = "http://192.168.1.124/prestashop/api/images/products/" . $idProduct . "/".$idImage."?ps_method=DELETE";
Upvotes: 2
Reputation: 4142
I found an example in the Prestashop webservice Library of deleting objects. Hope it'll help you out:
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.myshop.com/');
define('PS_WS_AUTH_KEY', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ');
require_once('./PSWebServiceLibrary.php');
if (isset($_GET['DeleteID']))
{
//Deletion
echo '<h1>Customers Deletion</h1><br>';
// We set a link to go back to list
echo '<a href="?">Return to the list</a>';
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Call for a deletion, we specify the resource name and the id of the resource in order to delete the item
$webService->delete(array('resource' => 'customers', 'id' => intval($_GET['DeleteID'])));
// If there's an error we throw an exception
echo 'Successfully deleted !<meta http-equiv="refresh" content="5"/>';
}
catch (PrestaShopWebserviceException $e)
{
// Here we are dealing with errors
$trace = $e->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 />'.$e->getMessage();
}
}
else
{
// Else get customers list
}
Source: Prestashop webservice examples
Upvotes: 0