Reputation: 331
i have a little problem with the Prestashop WebService. Could ypu helpme ? I'd like get all categories and subcategories of my shop with prestashop API. I 've followed instruction and read documentation an examples, but i'm confused about use of "children()" and "attributes()".
This is my code:
<?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';
}
?>
and then ? How can i retrieve name and id of category ? And how can i retrieve name, id and taxonomy of subcategories ?
Thanks in advance.
Upvotes: 0
Views: 6519
Reputation: 11
Check the rendering options in http://doc.prestashop.com/display/PS15/Chapter+8+-+Advanced+Use#Chapter8-AdvancedUse-RenderingOptions
You might have to use display option as well in $opt to get name or any other param apart from id...
Upvotes: 1
Reputation: 240
At this stage, Prestashop returns a collection of Category URLs. Then you have to call again Prestashop API on every single URL to get the actual category data with
$resources->id ; $resources->name->language[0][0];
Your internet browser is your friend. Try any command first with your browser to see what you get. I hope it helps.
Upvotes: 2