我對Prestashop WebService有一些問題。 可以幫忙嗎? 我想用prestashop API獲取我店的所有類別和子類別。 我遵循指令和閱讀文檔的一個例子,但我很困惑使用「children()」和「attributes()」。使用api prestashop獲取所有類別和子類別
這是我的代碼:
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_error', 1);
define('DEBUG', false); // Debug mode
define('PS_SHOP_PATH', 'http://localhost/myshop'); // Root path of your PrestaShop store
define('PS_WS_AUTH_KEY', '*********************************'); // Auth key (Get it in your Back Office)
require_once('api/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'] = 'categories';
// 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';
}
?>
然後? 如何檢索類別的名稱和編號? 我如何檢索子類別的名稱,ID和分類?
在此先感謝。
?顯示=全面的伎倆 – Petkovsky