* @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);
define('PS_SHOP_PATH', 'http://www.myshop.com/');
define('PS_WS_AUTH_KEY', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ');
require_once('../PSWebServiceLibrary.php');
// Here we use the WebService to get the schema of "customers" resource
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'customers');
if (isset($_GET['Create']))
$xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/customers?schema=blank'));
else
$xml = $webService->get($opt);
$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 '.$e->getMessage();
}
if (count($_POST) > 0)
{
// Here we have XML before update, lets update XML
foreach ($resources as $nodeKey => $node)
{
$resources->$nodeKey = $_POST[$nodeKey];
}
try
{
$opt = array('resource' => 'customers');
if ($_GET['Create'] == 'Creating')
{
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
echo "Successfully added.";
}
}
catch (PrestaShopWebserviceException $ex)
{
// Here we are dealing with errors
$trace = $ex->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 '.$ex->getMessage();
}
}
// We set the Title
echo '
';
// We set a link to go back to list if we are in creation
if (isset($_GET['Create']))
echo 'Return to the list';
if (!isset($_GET['Create']))
echo '';
else
echo '';
?>