For our geeXapp application, we needed a category selector. Rather than build something directly into the framework, we thought it would be convenient to build a category selector XML API that anyone could use (without eBay credentials) -- saving some implementation time.
Well, here it is. We're offering this with limited documentation because it's pretty self explanatory.
By passing a category ID in a $_GET variable named "CategoryID" to http://ebaycats.geexapp.com, you'll be returned an XML response containing the category details as well as a list of its subcategories.
Try it for the top level of categories!
The "SiteID" $_GET variable is also supported, but currently only eBay US categories are returned. (eBay Motors categories are in the works as well.)
If you don't want to fool with it at all, and just want a JavaScript widget as a category selector on your website, simply download these 2 files:
Then create a "redirect.php" file somewhere on your server [It MUST be on the same domain as the site using the category selector] with the following in it:
<?php
if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'geexapp-category-selector') { header ('Location: http://ebaycats.geexapp.com/',true,301); }
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, 'http://ebaycats.geexapp.com/?CategoryID='.(int)$_GET['CategoryID'].'&SiteID='.(int)$_GET['SiteID']);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec ($ch);
The redirect.php file is required because the category selector uses AJAX, and AJAX calls must be made within the same domain. Your webserver must have PHP enabled with cURL installed. Once the file is in place, modify the variable 'self.baseUrl' in category-selector.js to point to that file.
Include the category-selector.css stylesheet and category-selector.js script in your website header. Then, to activate a selector, use code something like:
var myVar = new categorySelector (objForIDOutput, objForNameOutput, optionalObjectContainers); myVar.fetch (0);
When the user selects a category, the objects you passed will have their innerHTML and value set as follows:
objForIDOutput: The category ID AND category name separated by a colon. Example: 1468;Really Weird objForNameOutput: The category name (usually for a field to show a user.) Example: Really Weird optionalObjectContainer: By default, the object is appended to the document body. If an object is passed here, it will be used instead.
That's all there is to it! The code should be relatively straightforward to modify to suit your needs. Otherwise, it is offered free to use and modify for all, but without warranty, etc.