Web 服务不显示任何内容

Web Service doesn't show anything

我想显示我商店中所有产品的名称和 ID,但无法正常工作。

这是我的代码:

<html><head><title>Prueba CRUD - Lista Productos</title></head><body>
<?php

// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);                                          // Debug mode
define('PS_SHOP_PATH','http://192.168.1.124/prestashop');       // Root path of your PrestaShop store
define('PS_WS_AUTH_KEY','xxx'); // Auth key (Get it in your Back Office)
require_once('./PSWebServiceLibrary.php');
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

// Here we set the option array for the Webservice : we want products resources
 $opt = array(
'resource' => 'products',
'display'  => '[id,name]'
);


// Call
$xml = $webService->get($opt);

// Here we get the elements from children of products 
$resources = $xml->products->children();
}
catch (Exception $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 "Se ha producido un error: <br/>". $e->getMessage();
}

// We set the Title
echo "<h1>Lista Productos</h1>";

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))
{
    echo '<tr><th>Id</th><th>Nombre</th></tr>';
    foreach ($resources as $resource)
    {
        echo '<tr><td>'.$resource->attributes().'</td>
        <td>'.$resource->attributes().'</td>
        </tr>';
    }
}
echo '</table>';
?>
</body></html>

如您所见,我使用 select id 和 name 的显示选项来显示它们,但我不知道如何使用结果并显示它。

嗨,如果有人有同样的问题,我用下面的代码解决了:

 if (isset($resources))
 {
    echo '<tr><th>Id</th><th>Nombre</th></tr>';
    foreach ($resources as $resource)
    {
        $probando = print_r($resource->name, true);
        echo '<tr><td>'.$resource->id.'</td>
        <td>'.$resource->name->language.'</td>
        </tr>';
    }
  }