Child pages
  • Chapter 7 - Removal - Remove customer accounts from the database
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Objective: A Web application for listing and deleting customers.
Difficulty: *
<span style="color: #79b51c"><strong>Preparation:</strong></span>
<span style="color: #0070c0">Duplicate</span> file <span style="color: #0070c0">list_the_clients.php</span> from Section 3.3 to a file named <span style="color: #0070c0">D-CRUD.php</span> at the root of your Web server.
For this last part, we will learn how to delete a resource.
try{
$webService = new PrestaShopWebservice('http://mystore.com/', 'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT', false); <span style="color: #0070c0">// Create an instance</span>
$opt[enEN:'resource'] = 'customers'; <span style="color: #0070c0">// Resource to use</span>
$opt[enEN:'id'] = 3; <span style="color: #0070c0">// ID to use</span>
$webService->delete($opt); <span style="color: #0070c0">// Delete</span>
echo 'Client '.3.' supprimé avec succès !'; <span style="color: #0070c0">// if we can see this message then</span>
<span style="color: #0070c0">// that means that we have not left the try block</span>
}
catch (PrestaShopWebserviceException $ex)
{
$trace = $ex->getTrace(); <span style="color: #0070c0">// Recuperate all info on this error</span>
$errorCode = $trace[enEN:0][enEN:'args'][enEN:0]; <span style="color: #0070c0">// Recuperate error code</span> if ($errorCode == 401)
echo 'Bad auth key'; else
echo 'Other error : <br />'.$ex->getMessage();
<span style="color: #0070c0">// Display error message</span>
}Here is the complete, detailed call you need to remove a client:
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 difference 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 an ID defined dynamically.
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."

  • No labels