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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
| <body>
<div class="container">
<h1>eBay Search Results</h1>
<div id="results"></div>
</div>
<script>
// Parse the response and build an HTML table to display search results
function _cb_findCompletedItems(root) {
var items = root.findCompletedItemsResponse[0].searchResult[0].item || [];
let dateChoose = new Date(<?= json_encode($dateChoose)?>);
console.log(dateChoose);
var somme = 0;
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var price = item.sellingStatus[0].convertedCurrentPrice[0].__value__;
let date = new Date(endTime);
while(date > dateChoose){
var salesNumber = items.length;
var somme += price;
}
var moyenne = somme/salesNumber;
}
var table = [];
table.push(
'<table><tr class="active><th>Nombre de vente</th><th>Moyenne de prix</th></tr>'+
'<tr><td>'+ salesNumber +'</td><td>' + moyenne+ '</td></tr></table>');
var html = [];
html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3 class="table table-bordered table-striped table-condensed"><tr><th>Photo</th><th>Label</th><th>Date de vente</th><th>Prix de vente</th></tr>');
for (var i = 0; i < items.length; ++i) {
var item = items[i];
var title = item.title;
var pic = item.galleryURL;
var viewitem = item.viewItemURL;
var price = item.sellingStatus[0].convertedCurrentPrice[0].__value__;
var endTime = item.listingInfo[0].endTime;
let date = new Date(endTime);
if (null != title && null != viewitem) {
html.push('<tr><td><img src="' + pic + '" border="0">' + '</td>' +
'<td><a href="' + viewitem + '" target="_blank">' + title + '</a></td>'
+'<td>'+ date + ' </td><td>'+price+'</td></tr>');
}
}
html.push('</table>');
document.getElementById("results").innerHTML = html.join("");
} // End _cb_findCompletedItems() function
// Create a JavaScript array of the item filters you want to use in your request
var filterarray = [
/*{"name":"MaxPrice",
"value":"25",
"paramName":"Currency",
"paramValue":"USD"},
{"name":"FreeShippingOnly",
"value":"true",
"paramName":"",
"paramValue":""},
{"name":"ListingType",
"value":["AuctionWithBIN", "FixedPrice", "StoreInventory"],
"paramName":"",
"paramValue":""},*/
{
"name" : "SoldItemsOnly",
"value" : "true",
"paramName" : '',
"paramValue" : ''
},
];
// Define global variable for the URL filter
var urlfilter = "";
// Generates an indexed URL snippet from the array of item filters
function buildURLArray() {
// Iterate through each filter in the array
for(var i=0; i<filterarray.length; i++) {
//Index each item filter in filterarray
var itemfilter = filterarray[i];
// Iterate through each parameter in each item filter
for(var index in itemfilter) {
// Check to see if the paramter has a value (some don't)
if (itemfilter[index] !== "") {
if (itemfilter[index] instanceof Array) {
for(var r=0; r<itemfilter[index].length; r++) {
var value = itemfilter[index][r];
urlfilter += "&itemFilter\(" + i + "\)." + index + "\(" + r + "\)=" + value ;
}
}
else {
urlfilter += "&itemFilter\(" + i + "\)." + index + "=" + itemfilter[index];
}
}
}
}
} // End buildURLArray() function
// Execute the function to build the URL filter
buildURLArray(filterarray);
var product = <?php echo json_encode($product); ?>;
// Construct the request
// Replace MyAppID with your Production AppID
var url = "http://svcs.ebay.com/services/search/FindingService/v1";
url += "?OPERATION-NAME=findCompletedItems";
url += "&SERVICE-VERSION=1.0.0";
url += "&SECURITY-APPNAME=Lemarcha-projetTo-PRD-f2ccbdebc-1b934df9";
url += "&GLOBAL-ID=EBAY-FR";
url += "&RESPONSE-DATA-FORMAT=JSON";
url += "&callback=_cb_findCompletedItems";
url += "&REST-PAYLOAD";
url += "&keywords="+encodeURI(product);;
url += "&paginationInput.entriesPerPage=25";
url += urlfilter;
//url += "&itemFilter(0).name=SoldItemsOnly";
//url += "&itemFilter(0).value=true";
//url += "&sortOrder=PricePlusShippingLowest";
// Submit the request
s=document.createElement('script'); // create script element
s.src= url;
document.body.appendChild(s);
// Display the request as a clickable link for testing
document.write("<a href=\"" + url + "\">" + url + "</a>");
</script>
</body> |
Partager