-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
48 lines (39 loc) · 1.64 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once './EbayHalfProductsAPI.php';
$appKey = '<INPUT YOUR APP KEY HERE>';
$encoding = 'JSON';
$apiCall = new EbayHalfProductsAPI($appKey, $encoding);
// sample input data
$sampleIds = [
['id' => '9780451524935', 'type' => 'EAN' ],
['id' => '9781419722868', 'type' => 'ISBN' ],
['id' => '075678252624', 'type' => 'UPC' ]
];
foreach ($sampleIds as $sampleId) {
// get the response from eBay API
$response = $apiCall->makeCall($sampleId['id'], $sampleId['type']);
// decode json to object
$json_response = json_decode($response);
// no products found
if (null === $json_response->Products) {
continue;
}
$products = $json_response->Products->Product[0]->ItemArray->Item;
echo '<h1>Found: ' . count($products) . ' products</h1>';
echo '<p>Search by ' . $sampleId['type'] . ': ' . $sampleId['id'] . '</p>';
echo '<table style="border: 1px solid #666; ">';
echo '<thead><th>Product ID</th><th>URL</th><th>Quantity</th><th>Country</th><th>Price</th><th>Condition</th></thead>';
echo '<tbody>';
foreach ($products as $product) {
echo '<tr>';
echo '<td>' . $product->ItemID . '</td>';
echo '<td><a target="_blank" href="' . $product->ViewItemURLForNaturalSearch . '">' . $product->ViewItemURLForNaturalSearch . '</a></td>';
echo '<td>' . $product->Quantity . '</td>';
echo '<td>' . $product->Country . '</td>';
echo '<td>' . $product->CurrentPrice->Value . ' ' . $product->CurrentPrice->CurrencyID . '</td>';
echo '<td>' . $product->HalfItemCondition . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}