-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcategories.php
37 lines (32 loc) · 1.18 KB
/
categories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require 'vendor/autoload.php';
use \DTS\eBaySDK\Shopping\Services;
use \DTS\eBaySDK\Shopping\Types;
// Create the service object.
$service = new Services\ShoppingService(array(
'apiVersion' => '863',
'appId' => EBAY_APP_ID
));
//Id is root so select default categories from DB
if($_GET['id'] == -1) {
$pdo = new PDO('mysql:host=localhost;dbname=ebay', 'root','');
$stmt = $pdo->prepare("SELECT * from categories");
$stmt->execute();
$results = $stmt->fetchAll();
} else {
// Create the request object.
$request = new Types\GetCategoryInfoRequestType(array('CategoryID' => $_GET['id'],'IncludeSelector' => 'ChildCategories'));
// Send the request to the service operation.
$response = $service->getCategoryInfo($request);
$results = array();
foreach($response->CategoryArray->Category as $category) {
if($category->CategoryName =='Root') continue;
array_push($results,
array('name'=>$category->CategoryName,
'id' => $category->CategoryID,
'parentId'=>$category->CategoryParentID
));
}
}
header('Content-Type: application/json');
echo json_encode(array('categories'=>$results));