Chapter 7 - Removal - Remove customer accounts from the database
Objective: A Web application for listing and deleting customers. Difficulty: *
Preparation
Duplicate file list_the_clients.php
from Section 3.3 to a file named D-CRUD.php
at the root of your Web server.
For this last part, we will learn how to delete a resource.
Here is the complete, detailed call you need to remove a client:
try {
$webService = new PrestaShopWebservice( '[http://mystore.com/|http://mystore.com/]' , 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT' , false ); // Create an instance{color}
$opt[ 'resource' ] = 'customers'; // Resource to use{color}
$opt[ 'id' ] = 3; // ID to use{color}
$webService->delete( $opt ); // Delete{color}
echo 'Client '.3.' successfully deleted!'; // If we can see this message then that means that we have not left the try block
}
catch (PrestaShopWebserviceException $ex) {
$trace = $ex->getTrace(); // Recuperate all info on this error
$errorCode = $trace[ 0 ][ 'args' ][ 0 ]; // Recuperate error code
if ( $errorCode == 401 )
echo 'Bad auth key';
else
echo 'Other error : <br />'.$ex->getMessage();
// Display error message{color}
}
This code allows you to remove a customer whose ID is "3". As you can see, deleting the customer differs only slightly from retrieving a resource. In fact the only thing different in the code lies in the method called: We will no longer call this method "get" but instead simply "delete"!
You must now replace the customer ID by a dynamically-defined ID.
Now create all the script that will display a list of customer IDs and delete a customer of your choice.
Again, if you have trouble, look at the code for 4-delete.php
.
Last updated
Was this helpful?