Jump to content

Retrieve firstname,lastname, company from customers with WebService ( API )


MAPVince

Recommended Posts

Hi everyone,

 

In advance i'm french, so sorry for my bad english. I'm gonna try to be understood as possible i can.

I want to retrieve the firstname, lastname, and company name, from a customer. I tried many thing but was unsuccessful.

 

Here you can found my php :

<?php 
define('DEBUG', true);
define('PS_SHOP_PATH','XXXXXXXXXXXXXXXXXXX');
define('PS_WS_AUTH_KEY', 'XXXXXXXXXXXXXXXXXXXXX');

// Appel la librairie à la racine pour acceder aux méthodes GET, POST, PUT, DELETE
require_once('./PSWebServiceLibrary.php'); 

try
{
	//Création d'une nouvelle instance de PrestaShopWebService
	$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
	//Création d'un tableau qui va contenir "customers"
	$opt['resource'] = 'customers';
	// Vérification si l'id est définit
	/*$opt = array('resource' => 'customers','display' => '[lastname]');*/
	if (isset($_GET['id']))
	{
		$opt['id'] = $_GET['id'];
		$opt['display'] = 'lastname';
	}
	$xml = $webService->get($opt);
	$resources = $xml->children()->children();
}
catch (PrestaShopWebServiceExeption $ex)
{
	$trace = $ex->getTrace(); // Récupère toutes les Informations sur l'erreur
	$errorCode = $trace[0]['args'][0]; // Récupération du code d'erreur
	if ($errorCode == 401)
		echo 'Bad auth key'; else
		echo 'Other error : <br />'.$ex->getMessage();
	// Affiche un message associé à l’erreur
}

echo '<h1>Liste des utilisateurs ';
if (isset($_GET['id']))
{
	echo 'Details';
}
else
{ 
	echo 'List';
}
echo '</h1>';
// We set a link to go back to list if we are in customer's details
if (isset($_GET['id'])){
	echo '<a href="?">Back</a>';
}
echo '<table border="5">';
//Si $resources est définie, on liste les éléments. Sinon, afficher erreur 
if (isset($resources))
{
	if (!isset($_GET['id']))
	{
		echo '<tr><th>Id</th><th>Détails</th></tr>';
		foreach ($resources as $resource)
		{
			
			echo '<tr><td>'.$resource->attributes().'</td><td>'.
			'<a href="?id='.$resource->attributes().'">Voir les détails</a>'.
			'</td></tr>';
		}
	}
	else
	{
		foreach ($resources as $key => $resource)
		{
			echo '<tr>';
			echo '<th>'.$key.'</th><td>'.$resource.'</td>';
			echo '</tr>';
		}
	}
}
else
{
	echo 'erreur';
}
echo '</table>';

?>

If anyone can help me with it i would be grateful.

If you need more information tell me !

Regards,

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...