PrestaShopWebservice::delete PHP Method

delete() public method

Unique parameter must take :

'resource' => Resource name
'id' => ID or array which contains IDs of a resource(s) you want to delete

delete(array('resource' => 'orders', 'id' => 1)); Following code will not be executed if an exception is thrown. echo 'Successfully deleted.'; } catch (PrestaShopWebserviceException $ex) { echo 'Error : '.$ex->getMessage(); } ?>
public delete ( array $options )
$options array Array representing resource to delete.
    public function delete($options)
    {
        if (isset($options['url'])) {
            $url = $options['url'];
        } elseif (isset($options['resource']) && isset($options['id'])) {
            if (is_array($options['id'])) {
                $url = $this->url . '/api/' . $options['resource'] . '/?id=[' . implode(',', $options['id']) . ']';
            } else {
                $url = $this->url . '/api/' . $options['resource'] . '/' . $options['id'];
            }
        }
        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'];
        }
        $request = self::executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'DELETE'));
        self::checkStatusCode($request['status_code']);
        // check the response validity
        return true;
    }

Usage Example

Example #1
0
* @package PrestaShopWebservice
*/
// 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();
            }
        }
    }