2014-01-25 65 views
0

我對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和分類?

在此先感謝。

回答

2

在此階段,Prestashop返回類別URL的集合。 然後,你必須再次呼籲每一個URL的Prestashop API與

$resources->id ; $resources->name->language[0][0]; 

你的瀏覽器是你的朋友,以獲得實際的類別數據。首先嚐試使用任何命令與您的瀏覽器,看看你得到什麼。 我希望它有幫助。

相關問題