forked from arthurchipdean/ebay-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
80 lines (67 loc) · 2.98 KB
/
search.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require 'vendor/autoload.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Finding\Services;
use \DTS\eBaySDK\Finding\Types;
use DTS\eBaySDK\Finding\Types\ItemFilter;
use DTS\eBaySDK\Finding\Types\PaginationInput;
$service = new Services\FindingService(array(
'appId' => EBAY_APP_ID,
'globalId' => Constants\GlobalIds::US
));
if(isset($_GET['category'])) {
$request = new Types\FindItemsAdvancedRequest();
$request->categoryId = array($_GET['category']);
}
else
$request = new Types\FindItemsByKeywordsRequest();
if(isset($_GET['MinBids']))
$request->itemFilter[]= new ItemFilter(array('name'=> 'MinBids', 'value' => array($_GET['MinBids'])));
if(isset($_GET['MaxBids']))
$request->itemFilter[]= new ItemFilter(array('name'=> 'MaxBids', 'value' => array($_GET['MaxBids'])));
if(isset($_GET['MinPrice']))
$request->itemFilter[]= new ItemFilter(array('name'=> 'MinPrice', 'value' => array($_GET['MinPrice'])));
if(isset($_GET['MaxPrice']))
$request->itemFilter[]= new ItemFilter(array('name'=> 'MaxPrice', 'value' => array($_GET['MaxPrice'])));
if(isset($_GET['sort']))
$request->sortOrder = $_GET['sort'];
if(isset($_GET['page'])) {
$request->paginationInput = new PaginationInput();
$request->paginationInput->pageNumber = (int)$_GET['page'];
}
if(isset($_GET['freeShipping']) && $_GET['freeShipping'])
$request->itemFilter []= new ItemFilter(array('name'=>'FreeShippingOnly','value' => array('true')));
if(isset($_GET['Auction']) || isset($_GET['BuyNow'])) {
$auction_types = array();
if(isset($_GET['Auction']) && $_GET['Auction'])
$auction_types[]='Auction';
if(isset($_GET['BuyNow']) && $_GET['BuyNow'])
$auction_types[]='FixedPrice';
$request->itemFilter[]= new ItemFilter(array('name'=>'ListingType','value'=>$auction_types));
}
$request->keywords = $_GET['q'];
if(isset($_GET['category']))
$response = $service->findItemsAdvanced($request);
else
$response = $service->findItemsByKeywords($request);
$result = array();
$now = new DateTime();
foreach ($response->searchResult->item as $item) {
$interval = $item->listingInfo->endTime->diff($now);
array_push($result, array(
'id' => $item->itemId,
'title' => $item->title,
'buyItPrice' => $item->listingInfo->buyItNowPrice,
'image' => $item->galleryURL,
'shipping' => $item->shippingInfo->shippingType,
'subtitle' => $item->subtitle,
'location' => $item->location,
'url' => $item->viewItemURL,
'currency' => $item->sellingStatus->currentPrice->currencyId,
'value' => $item->sellingStatus->currentPrice->value,
'remaining' => $interval->format("%d days, %h hours, %i minutes, %s seconds"),
'topRated' => $item->topRatedListing
));
}
header('Content-Type: application/json');
echo json_encode(array('results' => $result, 'count' =>$response->paginationOutput->totalEntries,'page' =>$response->paginationOutput->pageNumber ));