-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathRetrieve.php
101 lines (94 loc) · 3.19 KB
/
Retrieve.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html><head><title>CRUD Tutorial - Retrieve example</title></head><body>
<?php
/*
* 2007-2020 PrestaShop SA and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2020 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* PrestaShop Webservice Library
* @package PrestaShopWebservice
*/
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true); // Debug mode
define('PS_SHOP_PATH', 'http://www.myshop.com/'); // Root path of your PrestaShop store
define('PS_WS_AUTH_KEY', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ'); // Auth key (Get it in your Back Office)
require_once('../PSWebServiceLibrary.php');
// Here we make the WebService Call
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Here we set the option array for the Webservice : we want customers resources
$opt['resource'] = 'customers';
// We set an id if we want to retrieve infos from a customer
if (isset($_GET['id']))
$opt['id'] = (int)$_GET['id']; // cast string => int for security measures
// Call
$xml = $webService->get($opt);
// Here we get the elements from children of customer markup which is children of prestashop root markup
$resources = $xml->children()->children();
}
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();
}
// We set the Title
echo '<h1>Customers ';
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="?">Return to the list</a>';
echo '<table border="5">';
// if $resources is set we can lists element in it otherwise do nothing cause there's an error
if (isset($resources))
{
if (!isset($_GET['id']))
{
echo '<tr><th>Id</th><th>More</th></tr>';
foreach ($resources as $resource)
{
// Iterates on the found IDs
echo '<tr><td>'.$resource->attributes().'</td><td>'.
'<a href="?id='.$resource->attributes().'">Retrieve</a>'.
'</td></tr>';
}
}
else
{
foreach ($resources as $key => $resource)
{
// Iterates on customer's properties
echo '<tr>';
echo '<th>'.$key.'</th><td>'.$resource.'</td>';
echo '</tr>';
}
}
}
echo '</table>';
?>
</body></html>