2 |
- |
1 |
<!DOCTYPE html>
|
|
|
2 |
<html lang="en">
|
|
|
3 |
|
|
|
4 |
<head>
|
|
|
5 |
<title>eBay Listings Price Check</title>
|
|
|
6 |
<meta charset="UTF-8">
|
|
|
7 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
8 |
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
|
|
|
9 |
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
|
|
10 |
|
30 |
- |
11 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
|
|
|
12 |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
|
|
|
13 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
|
14 |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
|
|
|
15 |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
|
|
|
16 |
<script src="js/XMLWriter.js"></script>
|
|
|
17 |
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
|
|
|
18 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script>
|
|
|
19 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data-2012-2022.min.js"></script>
|
2 |
- |
20 |
<link rel="stylesheet" href="css/style.css">
|
|
|
21 |
<script src="js/muna-tools.js"></script>
|
|
|
22 |
</head>
|
|
|
23 |
|
|
|
24 |
<body onload="return initConfig();">
|
30 |
- |
25 |
<div>
|
|
|
26 |
<div>
|
|
|
27 |
<div class="container-fluid bg-secondary">
|
|
|
28 |
<div class="clearfix">
|
|
|
29 |
<img class="img-fluid float-right" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" />
|
|
|
30 |
<h1 id="connected">eBay Listings Price Check
|
|
|
31 |
<input id="login" type="button" class="btn bg-success mb-2 w3-hide" onclick="eBayLogin();" value="Login" /></h1>
|
|
|
32 |
</div>
|
2 |
- |
33 |
</div>
|
|
|
34 |
|
30 |
- |
35 |
<div class="border col">
|
2 |
- |
36 |
<div>
|
30 |
- |
37 |
<form id="searchForm" class="container-fluid bg-light" onsubmit="return checkListingPrices();">
|
|
|
38 |
<input id="startButton" type="button" class="btn btn-dark" onclick="checkListingPrices();" value="Start" />
|
2 |
- |
39 |
</form>
|
|
|
40 |
</div>
|
30 |
- |
41 |
<div class="modal" id="progressBarDiv">
|
|
|
42 |
<div class="modal-dialog">
|
|
|
43 |
<div class="modal-content">
|
|
|
44 |
<div class="modal-header">
|
|
|
45 |
<h4 id="progressBarHeader"></h4>
|
|
|
46 |
</div>
|
|
|
47 |
<div class="modal-body">
|
|
|
48 |
<div class="progress">
|
|
|
49 |
<div id="progressBar" class="progress-bar" style="width:0%">0%</div>
|
|
|
50 |
</div>
|
|
|
51 |
</div>
|
|
|
52 |
</div>
|
2 |
- |
53 |
</div>
|
|
|
54 |
</div>
|
30 |
- |
55 |
<div id="results" class="border bg-info w3-hide"></div>
|
|
|
56 |
<div id="logging"></div>
|
2 |
- |
57 |
</div>
|
|
|
58 |
</div>
|
|
|
59 |
|
30 |
- |
60 |
<footer class="container-fluid text-center border border-bottom-0 border-left-0 border-right-0">
|
17 |
- |
61 |
<div w3-include-html="php/footer.php"></div>
|
2 |
- |
62 |
</footer>
|
|
|
63 |
|
|
|
64 |
</div>
|
6 |
- |
65 |
|
2 |
- |
66 |
<script>
|
|
|
67 |
|
|
|
68 |
// Config
|
|
|
69 |
var configMinPrice = "5.99";
|
|
|
70 |
var configDifference = 2.00;
|
|
|
71 |
var configPercentage = 20.00;
|
|
|
72 |
var configAbsoluteMinPrice = 5.00;
|
|
|
73 |
var configAdjMinPrice = 5.48;
|
193 |
- |
74 |
var configSearchUrl = 'https://dev.munatrading.com/ebay/search.html?keyword=';
|
2 |
- |
75 |
var configSearchUrlPart2 = '&hideDuplicateItems=on&locatedIn=WorldWide&sortOrder=PricePlusShippingLowest&results=100';
|
|
|
76 |
|
|
|
77 |
var pagesToProcess = 0;
|
|
|
78 |
var maxPagesToProcess = 0;
|
|
|
79 |
var pagesProcessed = 0;
|
|
|
80 |
var productIdsToProcess = 0;
|
|
|
81 |
var maxProductIdsToProcess = 0;
|
|
|
82 |
var productIdsProcessed = 0;
|
|
|
83 |
var productsToPrice = 0;
|
|
|
84 |
var maxProductsToPrice = 0;
|
|
|
85 |
var productsPriced = 0;
|
|
|
86 |
var html = [];
|
180 |
- |
87 |
var eBaySearchCount = [];
|
|
|
88 |
var productPricesCount = [];
|
2 |
- |
89 |
|
|
|
90 |
// Initialize Configuration Variables
|
|
|
91 |
function initConfig() {
|
|
|
92 |
eBayAuthToken = readCookie();
|
|
|
93 |
if (eBayAuthToken.length > 0) {
|
|
|
94 |
connected();
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
if (eBayAuthTokenFlag === false) {
|
|
|
98 |
var x = document.getElementById("login");
|
|
|
99 |
if (x.className.indexOf("w3-show") == -1) {
|
|
|
100 |
x.className += " w3-show";
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
function requireNewLogin() {
|
|
|
106 |
// dummy
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
function checkListingPrices() {
|
|
|
110 |
var x;
|
|
|
111 |
|
|
|
112 |
document.getElementById("logging").innerHTML = '';
|
|
|
113 |
|
|
|
114 |
x = document.getElementById("results");
|
|
|
115 |
if (x.className.indexOf("w3-show") == -1) {
|
|
|
116 |
x.className += " w3-show";
|
|
|
117 |
}
|
|
|
118 |
x.className = x.className.replace(" process-errors", "");
|
|
|
119 |
x.innerHTML = '';
|
|
|
120 |
|
|
|
121 |
initProgressBar('Retrieving Active Listings (1/3)');
|
|
|
122 |
|
|
|
123 |
pagesToProcess = 1;
|
|
|
124 |
maxPagesToProcess = 1;
|
|
|
125 |
pagesProcessed = 0;
|
180 |
- |
126 |
eBaySearchCount = [];
|
|
|
127 |
eBaySearchCount[1] = 0;
|
2 |
- |
128 |
eBaySearch(1);
|
|
|
129 |
|
|
|
130 |
function checkpagesToProcess() {
|
|
|
131 |
if (pagesToProcess > 0) {
|
180 |
- |
132 |
window.setTimeout(checkpagesToProcess, 250); // wait 100 milliseconds
|
2 |
- |
133 |
} else {
|
|
|
134 |
findMissingProductIds();
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
checkpagesToProcess();
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
// item filters for request
|
|
|
142 |
var filterarray = [];
|
|
|
143 |
var urlfilter = [];
|
|
|
144 |
|
|
|
145 |
// Fill the array of item filters from input form
|
|
|
146 |
function fillFilterArray() {
|
|
|
147 |
filterarray = [];
|
|
|
148 |
var obj = [];
|
|
|
149 |
|
|
|
150 |
obj = {
|
|
|
151 |
"name": "Seller",
|
|
|
152 |
"value": configeBaySellerName,
|
|
|
153 |
"paramName": "",
|
|
|
154 |
"paramValue": ""
|
|
|
155 |
};
|
|
|
156 |
filterarray.push(obj);
|
|
|
157 |
|
|
|
158 |
obj = {
|
|
|
159 |
"name": "MinPrice",
|
|
|
160 |
"value": Number(configMinPrice).toFixed(2),
|
|
|
161 |
"paramName": "Currency",
|
|
|
162 |
"paramValue": "USD"
|
|
|
163 |
};
|
|
|
164 |
filterarray.push(obj);
|
|
|
165 |
|
|
|
166 |
obj = {
|
|
|
167 |
"name": "ListingType",
|
|
|
168 |
"value": "FixedPrice",
|
|
|
169 |
"paramName": "",
|
|
|
170 |
"paramValue": ""
|
|
|
171 |
};
|
|
|
172 |
filterarray.push(obj);
|
|
|
173 |
|
|
|
174 |
urlfilter = "";
|
|
|
175 |
// Iterate through each filter in the array
|
|
|
176 |
for (var i = 0; i < filterarray.length; i++) {
|
|
|
177 |
//Index each item filter in filterarray
|
|
|
178 |
var itemfilter = filterarray[i];
|
|
|
179 |
// Iterate through each parameter in each item filter
|
|
|
180 |
for (var index in itemfilter) {
|
|
|
181 |
// Check to see if the paramter has a value (some don't)
|
|
|
182 |
if (itemfilter[index] !== "") {
|
|
|
183 |
if (itemfilter[index] instanceof Array) {
|
|
|
184 |
for (var r = 0; r < itemfilter[index].length; r++) {
|
|
|
185 |
var value = itemfilter[index][r];
|
|
|
186 |
urlfilter += "&itemFilter\(" + i + "\)." + index + "\(" + r + "\)=" + value;
|
|
|
187 |
}
|
|
|
188 |
} else {
|
|
|
189 |
urlfilter += "&itemFilter\(" + i + "\)." + index + "=" + itemfilter[index];
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
} // End fillFilterArray() function
|
|
|
195 |
|
|
|
196 |
var url = "";
|
|
|
197 |
|
|
|
198 |
function eBaySearch(pageNumber) {
|
180 |
- |
199 |
++eBaySearchCount[pageNumber];
|
|
|
200 |
|
2 |
- |
201 |
// Fill the filter array from form input
|
|
|
202 |
if (pageNumber == 1) {
|
|
|
203 |
fillFilterArray();
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
// Construct the request
|
|
|
207 |
url = configeBayFinding + "?";
|
|
|
208 |
url += "OPERATION-NAME=findItemsAdvanced";
|
|
|
209 |
url += "&SERVICE-VERSION=" + configeBayFindingVersion;
|
|
|
210 |
url += "&SECURITY-APPNAME=" + configAppid;
|
|
|
211 |
url += "&GLOBAL-ID=EBAY-US";
|
|
|
212 |
url += "&RESPONSE-DATA-FORMAT=JSON";
|
|
|
213 |
url += "&REST-PAYLOAD";
|
|
|
214 |
url += "&paginationInput.entriesPerPage=100";
|
|
|
215 |
url += "&paginationInput.pageNumber=";
|
|
|
216 |
url += pageNumber;
|
|
|
217 |
url += urlfilter;
|
|
|
218 |
|
|
|
219 |
var xhttp = new XMLHttpRequest();
|
|
|
220 |
|
|
|
221 |
xhttp.onreadystatechange = function() {
|
|
|
222 |
if (this.readyState == 4) {
|
180 |
- |
223 |
if (this.status == 200) {
|
|
|
224 |
_cb_findItemsAdvanced(JSON.parse(this.responseText));
|
|
|
225 |
} else {
|
|
|
226 |
if (eBaySearchCount[pageNumber] <= 5) {
|
|
|
227 |
window.setTimeout(function(){eBaySearch(pageNumber);}, 5000);
|
|
|
228 |
} else {
|
|
|
229 |
--pagesToProcess;
|
|
|
230 |
++pagesProcessed;
|
|
|
231 |
updateProgressBar(maxPagesToProcess, pagesProcessed);
|
|
|
232 |
window.setTimeout(function(){eBaySearchCount[pageNumber+1]=0;eBaySearch(pageNumber+1);}, 5000);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
2 |
- |
236 |
}
|
|
|
237 |
};
|
|
|
238 |
|
|
|
239 |
xhttp.open("GET", configProxyUrl, true);
|
|
|
240 |
xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
|
|
|
241 |
xhttp.send();
|
|
|
242 |
|
|
|
243 |
return false;
|
|
|
244 |
}
|
|
|
245 |
|
4 |
- |
246 |
function printeBayAPIError(str, root) {
|
2 |
- |
247 |
var x = document.getElementById("results");
|
|
|
248 |
x.className += " process-errors";
|
4 |
- |
249 |
x.innerHTML += "<h2>eBay API Error (" + str + ")<h2>";
|
2 |
- |
250 |
x.innerHTML += "<p>Id: " + root.errorMessage[0].error[0].errorId + "<br/>";
|
|
|
251 |
x.innerHTML += "<p>Severity: " + root.errorMessage[0].error[0].severity + "<br/>";
|
|
|
252 |
x.innerHTML += "<p>Message: " + root.errorMessage[0].error[0].message + "</p>";
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
// Parse the response and build an HTML table to display search results
|
|
|
256 |
function _cb_findItemsAdvanced(root) {
|
|
|
257 |
// Error Handling
|
|
|
258 |
var response = root.findItemsAdvancedResponse[0];
|
|
|
259 |
var ack = response.ack;
|
|
|
260 |
if (ack != 'Success') {
|
4 |
- |
261 |
printeBayAPIError('Find Item', response);
|
2 |
- |
262 |
|
|
|
263 |
if (ack == 'Failure' || ack == 'PartialFailure') {
|
|
|
264 |
--pagesToProcess;
|
|
|
265 |
return;
|
|
|
266 |
}
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
createTable(response.searchResult[0].item || [], Number(response.paginationOutput[0].pageNumber), Number(response.paginationOutput[0].totalPages));
|
|
|
270 |
|
6 |
- |
271 |
if (Number(response.paginationOutput[0].totalPages) > Number(response.paginationOutput[0].pageNumber)) {
|
|
|
272 |
++maxPagesToProcess;
|
|
|
273 |
++pagesToProcess;
|
180 |
- |
274 |
eBaySearchCount[Number(response.paginationOutput[0].pageNumber) + 1] = 0;
|
6 |
- |
275 |
eBaySearch(Number(response.paginationOutput[0].pageNumber) + 1);
|
|
|
276 |
}
|
2 |
- |
277 |
|
|
|
278 |
document.getElementById("logging").innerHTML = html.join('');
|
|
|
279 |
--pagesToProcess;
|
|
|
280 |
++pagesProcessed;
|
|
|
281 |
updateProgressBar(maxPagesToProcess, pagesProcessed);
|
|
|
282 |
} // End _cb_findItemsAdvanced() function
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
function createTable(obj, pageNumber, totalPages) {
|
|
|
286 |
if (pageNumber == 1) {
|
|
|
287 |
document.getElementById("logging").innerHTML = '';
|
|
|
288 |
html = [];
|
|
|
289 |
|
30 |
- |
290 |
html.push('<div class="border table-responsive">');
|
2 |
- |
291 |
html.push('<h3>Price Validation</h3>');
|
30 |
- |
292 |
html.push('<table id="itemTable" class="table table-hover table-striped table-bordered small css-serial">');
|
|
|
293 |
html.push('<thead class="thead-dark">');
|
2 |
- |
294 |
html.push('<tr>');
|
|
|
295 |
|
|
|
296 |
html.push(tableHeader('#'));
|
|
|
297 |
html.push(tableHeader('Item Id'));
|
|
|
298 |
html.push(tableHeader('Thumbnail'));
|
|
|
299 |
html.push(tableHeader('Title'));
|
|
|
300 |
html.push(tableHeader('Product Id'));
|
|
|
301 |
html.push(tableHeader('Price'));
|
|
|
302 |
html.push(tableHeader('# Active Listings'));
|
|
|
303 |
html.push(tableHeader('# Priced Lower'));
|
|
|
304 |
html.push(tableHeader('Lowest Price'));
|
|
|
305 |
html.push(tableHeader('Highest Price'));
|
|
|
306 |
html.push(tableHeader('Above/Below Lowest'));
|
|
|
307 |
html.push(tableHeader('Views'));
|
|
|
308 |
html.push(tableHeader('Watchers'));
|
|
|
309 |
html.push(tableHeaderHidden('Condition'));
|
|
|
310 |
html.push(tableHeaderHidden('# Better Condition'));
|
|
|
311 |
html.push(tableHeader('Price Adj.'));
|
|
|
312 |
html.push(tableHeaderHidden('Best Offer'));
|
|
|
313 |
html.push(tableHeaderHidden('MinBetterCondition'));
|
|
|
314 |
html.push(tableHeaderHidden('BetterConditionBreakdown'));
|
|
|
315 |
html.push(tableHeaderHidden('SameConditionBreakdown'));
|
|
|
316 |
|
|
|
317 |
html.push('</tr>');
|
|
|
318 |
html.push('</thead>');
|
|
|
319 |
html.push('<tbody>');
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
for (var entry = 0; entry < obj.length; entry++) {
|
|
|
323 |
html.push('<tr>');
|
|
|
324 |
html.push(tableCell(''));
|
|
|
325 |
html.push(tableCell('<a href="' + obj[entry].viewItemURL + '" target="_blank">' + obj[entry].itemId + '</a>'));
|
|
|
326 |
html.push(tableCell('<img src="' + obj[entry].galleryURL[0].replace('http:', 'https:') + '">'));
|
|
|
327 |
html.push(tableCell(obj[entry].title));
|
|
|
328 |
if (obj[entry].productId !== undefined) {
|
|
|
329 |
var str = '<a href="' + configSearchUrl;
|
|
|
330 |
str += 'ReferenceID%3A' + obj[entry].productId[0].__value__;
|
|
|
331 |
str += configSearchUrlPart2 + '" target="_blank">';
|
|
|
332 |
str += obj[entry].productId[0]["@type"] + ' ' + obj[entry].productId[0].__value__;
|
|
|
333 |
str += '</a>';
|
|
|
334 |
html.push(tableCell(str));
|
|
|
335 |
} else {
|
|
|
336 |
html.push(tableCellLabel('ProductId' + obj[entry].itemId));
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
html.push(tableCell('$' + Number(obj[entry].sellingStatus[0].convertedCurrentPrice[0].__value__).toFixed(2)));
|
|
|
340 |
html.push(tableCell(1));
|
|
|
341 |
html.push(tableCell(0));
|
|
|
342 |
html.push(tableCell('$0.00'));
|
|
|
343 |
html.push(tableCell('$0.00'));
|
|
|
344 |
html.push(tableCell('$0.00 (0.00%)'));
|
|
|
345 |
|
|
|
346 |
html.push(tableCell(0));
|
|
|
347 |
html.push(tableCell(obj[entry].listingInfo[0].watchCount === undefined ? 0 : Number(obj[entry].listingInfo[0].watchCount)));
|
|
|
348 |
html.push(tableCellHidden(obj[entry].condition === undefined ? 4000 : Number(obj[entry].condition[0].conditionId)));
|
|
|
349 |
html.push(tableCellHidden(0));
|
30 |
- |
350 |
html.push(tableCell('<input id="PriceAdj' + obj[entry].itemId + '" type="text" size="10"><br><input type="button" class="btn btn-dark" onclick="changePrice(' + obj[entry].itemId + ');" value="Adjust Price" />'));
|
2 |
- |
351 |
html.push(tableCellLabelHidden('BestOffer' + obj[entry].itemId, obj[entry].listingInfo[0].bestOfferEnabled));
|
|
|
352 |
html.push(tableCellHidden('0'));
|
|
|
353 |
html.push(tableCellHidden('[]'));
|
|
|
354 |
html.push(tableCellHidden('[]'));
|
|
|
355 |
|
|
|
356 |
html.push('</tr>');
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
if (pageNumber == totalPages) {
|
|
|
360 |
html.push('</tbody>');
|
|
|
361 |
html.push('</table>');
|
|
|
362 |
html.push('</div>');
|
|
|
363 |
}
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
function setCellsAttribute(table, row, col, label) {
|
|
|
367 |
table.rows[row].cells[col].setAttribute("id", label);
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
function sortTableDesc(tableName, column) {
|
|
|
371 |
var table, rows, switching, i, x, y, shouldSwitch;
|
|
|
372 |
--column; // column parameter starts with 1
|
|
|
373 |
table = document.getElementById(tableName);
|
|
|
374 |
switching = true;
|
|
|
375 |
/*Make a loop that will continue until
|
|
|
376 |
no switching has been done:*/
|
|
|
377 |
while (switching) {
|
|
|
378 |
//start by saying: no switching is done:
|
|
|
379 |
switching = false;
|
|
|
380 |
rows = table.getElementsByTagName("TR");
|
|
|
381 |
/*Loop through all table rows (except the
|
|
|
382 |
first, which contains table headers:*/
|
|
|
383 |
for (i = 1; i < (rows.length - 1); i++) {
|
|
|
384 |
//start by saying there should be no switching:
|
|
|
385 |
shouldSwitch = false;
|
|
|
386 |
/*Get the two elements you want to compare,
|
|
|
387 |
one from current row and one from the next:*/
|
|
|
388 |
x = rows[i].getElementsByTagName("TD")[column];
|
|
|
389 |
y = rows[i + 1].getElementsByTagName("TD")[column];
|
|
|
390 |
//check if the two rows should switch place:
|
|
|
391 |
if (x !== undefined && (Number(x.innerHTML.substr(1)) < Number(y.innerHTML.substr(1)))) {
|
|
|
392 |
//if so, mark as a switch and break the loop:
|
|
|
393 |
shouldSwitch = true;
|
|
|
394 |
break;
|
|
|
395 |
}
|
|
|
396 |
}
|
|
|
397 |
if (shouldSwitch) {
|
|
|
398 |
/*If a switch has been marked, make the switch
|
|
|
399 |
and mark that a switch has been done:*/
|
|
|
400 |
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
|
|
|
401 |
switching = true;
|
|
|
402 |
}
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
function findMissingProductIds() {
|
|
|
407 |
var i;
|
|
|
408 |
var x = document.getElementById("itemTable");
|
|
|
409 |
var missingList = [];
|
|
|
410 |
var viewList = [];
|
|
|
411 |
var maxItems = 20;
|
|
|
412 |
|
|
|
413 |
initProgressBar('Retrieving Product Ids (2/3)');
|
|
|
414 |
|
|
|
415 |
productIdsToProcess = 0;
|
|
|
416 |
maxProductIdsToProcess = 0;
|
|
|
417 |
productIdsProcessed = 0;
|
|
|
418 |
|
|
|
419 |
for (i = 1; i < x.rows.length; i++) {
|
|
|
420 |
if (x.rows[i].cells[4] !== undefined && x.rows[i].cells[4].innerText.length < 1) {
|
|
|
421 |
missingList.push(x.rows[i].cells[1].innerText);
|
|
|
422 |
} else {
|
|
|
423 |
var p = x.rows[i].cells[4].innerText.substr(x.rows[i].cells[4].innerText.indexOf(" ") + 1);
|
|
|
424 |
setCellsAttribute(x, i, 5, "Price" + p);
|
|
|
425 |
setCellsAttribute(x, i, 6, "Active" + p);
|
|
|
426 |
setCellsAttribute(x, i, 7, "Lower" + p);
|
|
|
427 |
setCellsAttribute(x, i, 8, "Minimum" + p);
|
|
|
428 |
setCellsAttribute(x, i, 9, "Maximum" + p);
|
|
|
429 |
setCellsAttribute(x, i, 11, "Views" + x.rows[i].cells[1].innerText);
|
|
|
430 |
setCellsAttribute(x, i, 13, "Condition" + p);
|
|
|
431 |
setCellsAttribute(x, i, 14, "BetterCondition" + p);
|
|
|
432 |
setCellsAttribute(x, i, 17, "MinBetterCondition" + p);
|
|
|
433 |
setCellsAttribute(x, i, 18, "BetterConditionBreakdown" + p);
|
|
|
434 |
setCellsAttribute(x, i, 19, "SameConditionBreakdown" + p);
|
|
|
435 |
viewList.push(x.rows[i].cells[1].innerText);
|
|
|
436 |
}
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
for (i = 0;
|
|
|
440 |
(i * maxItems) < missingList.length; i++) {
|
|
|
441 |
++productIdsToProcess;
|
|
|
442 |
++maxProductIdsToProcess;
|
|
|
443 |
findMissingProductId(missingList.slice(i * maxItems, (i + 1) * maxItems));
|
|
|
444 |
}
|
|
|
445 |
|
|
|
446 |
for (i = 0;
|
|
|
447 |
(i * maxItems) < viewList.length; i++) {
|
|
|
448 |
++productIdsToProcess;
|
|
|
449 |
++maxProductIdsToProcess;
|
|
|
450 |
findViews(viewList.slice(i * maxItems, (i + 1) * maxItems));
|
|
|
451 |
}
|
|
|
452 |
|
|
|
453 |
function checkproductIdsToProcess() {
|
|
|
454 |
if (productIdsToProcess > 0) {
|
180 |
- |
455 |
window.setTimeout(checkproductIdsToProcess, 250); // wait 100 milliseconds
|
2 |
- |
456 |
} else {
|
|
|
457 |
priceProductIds();
|
|
|
458 |
}
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
checkproductIdsToProcess();
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
function findMissingProductId(itemIdList) {
|
|
|
465 |
var i;
|
|
|
466 |
var xml;
|
|
|
467 |
|
|
|
468 |
var xw = new XMLWriter('UTF-8', '1.0');
|
|
|
469 |
var xhr = new XMLHttpRequest();
|
|
|
470 |
|
|
|
471 |
xw.writeStartDocument();
|
|
|
472 |
xw.writeStartElement("GetMultipleItemsRequest");
|
|
|
473 |
xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
|
|
|
474 |
|
|
|
475 |
for (i = 0; i < itemIdList.length; i++) {
|
|
|
476 |
xw.writeElementString('ItemID', itemIdList[i]);
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
xw.writeElementString('IncludeSelector', 'Details');
|
|
|
480 |
xw.writeElementString('ErrorLanguage', 'en_US');
|
|
|
481 |
xw.writeElementString('Version', configeBayShoppingVersion);
|
|
|
482 |
xw.writeElementString('WarningLevel', configWarningLevel);
|
|
|
483 |
|
|
|
484 |
xw.writeEndElement(); /* xmlrequest */
|
|
|
485 |
xw.writeEndDocument();
|
|
|
486 |
|
|
|
487 |
xhr.open('POST', configProxyUrl, true);
|
|
|
488 |
xhr.setRequestHeader('Content-Type', 'text/xml');
|
|
|
489 |
xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
|
|
|
490 |
xhr.setRequestHeader('X-EBAY-API-VERSION', configeBayShoppingVersion);
|
|
|
491 |
xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'GetMultipleItems');
|
|
|
492 |
xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
|
|
|
493 |
xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
|
|
|
494 |
xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
|
|
|
495 |
xhr.setRequestHeader('X-EBAY-API-REQUEST-ENCODING', 'XML');
|
|
|
496 |
xhr.setRequestHeader('X-Proxy-URL', configeBayShopping);
|
|
|
497 |
|
|
|
498 |
xml = xw.flush();
|
|
|
499 |
xw.close();
|
|
|
500 |
|
|
|
501 |
xhr.onload = function() {
|
17 |
- |
502 |
var jsonObj = XMLparse(xhr.responseXML, false);
|
|
|
503 |
var obj = jsonObj.GetMultipleItemsResponse;
|
2 |
- |
504 |
var returnCode = obj.Ack;
|
19 |
- |
505 |
var str;
|
2 |
- |
506 |
|
|
|
507 |
var x = document.getElementById("results");
|
|
|
508 |
|
|
|
509 |
if (returnCode == 'Success') {
|
|
|
510 |
for (i = 0; i < obj.Item.length; i++) {
|
|
|
511 |
var ItemID = getJsonValue(obj.Item[i].ItemID);
|
|
|
512 |
var SKU = getJsonValue(obj.Item[i].SKU);
|
|
|
513 |
var HitCount = getJsonValue(obj.Item[i].HitCount);
|
|
|
514 |
var n = (SKU === undefined ? 0 : SKU.indexOf(" - "));
|
|
|
515 |
var row;
|
|
|
516 |
var str;
|
|
|
517 |
var code;
|
|
|
518 |
|
|
|
519 |
if (n > 0) {
|
|
|
520 |
code = SKU.substr(n + 3);
|
|
|
521 |
code = code.substr(code.indexOf(" ") + 1);
|
|
|
522 |
str = '<a href="' + configSearchUrl;
|
|
|
523 |
str += code;
|
|
|
524 |
str += configSearchUrlPart2 + '" target="_blank">';
|
|
|
525 |
str += SKU.substr(n + 3);
|
|
|
526 |
str += '</a>';
|
|
|
527 |
document.getElementById('ProductId' + ItemID).innerHTML = str;
|
|
|
528 |
x = document.getElementById("itemTable");
|
|
|
529 |
row = document.getElementById('ProductId' + ItemID).parentNode.rowIndex;
|
|
|
530 |
setCellsAttribute(x, row, 5, "Price" + code);
|
|
|
531 |
setCellsAttribute(x, row, 6, "Active" + code);
|
|
|
532 |
setCellsAttribute(x, row, 7, "Lower" + code);
|
|
|
533 |
setCellsAttribute(x, row, 8, "Minimum" + code);
|
|
|
534 |
setCellsAttribute(x, row, 9, "Maximum" + code);
|
|
|
535 |
x.rows[row].cells[11].innerHTML = HitCount;
|
|
|
536 |
setCellsAttribute(x, row, 13, "Condition" + code);
|
|
|
537 |
setCellsAttribute(x, row, 14, "BetterCondition" + code);
|
|
|
538 |
setCellsAttribute(x, row, 17, "MinBetterCondition" + code);
|
|
|
539 |
setCellsAttribute(x, row, 18, "BetterConditionBreakdown" + code);
|
|
|
540 |
setCellsAttribute(x, row, 19, "SameConditionBreakdown" + code);
|
|
|
541 |
} else {
|
|
|
542 |
row = document.getElementById('ProductId' + ItemID).parentNode.rowIndex;
|
|
|
543 |
document.getElementById("itemTable").deleteRow(row);
|
|
|
544 |
}
|
|
|
545 |
}
|
|
|
546 |
} else {
|
|
|
547 |
x.className += " process-errors";
|
30 |
- |
548 |
str += '<p class="text-danger"><strong>' + returnCode + ':</strong></p>';
|
2 |
- |
549 |
|
6 |
- |
550 |
var errors = getJsonArray(obj.Errors);
|
19 |
- |
551 |
str += "<p>";
|
6 |
- |
552 |
for (i = 0; i < errors.length; i++) {
|
19 |
- |
553 |
str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
|
2 |
- |
554 |
}
|
19 |
- |
555 |
str += "</p>";
|
|
|
556 |
x.innerHTML += str;
|
2 |
- |
557 |
}
|
|
|
558 |
|
|
|
559 |
--productIdsToProcess;
|
|
|
560 |
++productIdsProcessed;
|
|
|
561 |
updateProgressBar(maxProductIdsToProcess, productIdsProcessed);
|
|
|
562 |
};
|
|
|
563 |
|
|
|
564 |
xhr.send(xml);
|
|
|
565 |
}
|
|
|
566 |
|
|
|
567 |
function findViews(itemIdList) {
|
|
|
568 |
var i;
|
|
|
569 |
var xml;
|
|
|
570 |
|
|
|
571 |
var xw = new XMLWriter('UTF-8', '1.0');
|
|
|
572 |
var xhr = new XMLHttpRequest();
|
|
|
573 |
|
|
|
574 |
xw.writeStartDocument();
|
|
|
575 |
xw.writeStartElement("GetMultipleItemsRequest");
|
|
|
576 |
xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
|
|
|
577 |
|
|
|
578 |
for (i = 0; i < itemIdList.length; i++) {
|
|
|
579 |
xw.writeElementString('ItemID', itemIdList[i]);
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
xw.writeElementString('ErrorLanguage', 'en_US');
|
|
|
583 |
xw.writeElementString('Version', configeBayShoppingVersion);
|
|
|
584 |
xw.writeElementString('WarningLevel', configWarningLevel);
|
|
|
585 |
|
|
|
586 |
xw.writeEndElement(); /* xmlrequest */
|
|
|
587 |
xw.writeEndDocument();
|
|
|
588 |
|
|
|
589 |
xhr.open('POST', configProxyUrl, true);
|
|
|
590 |
xhr.setRequestHeader('Content-Type', 'text/xml');
|
|
|
591 |
xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
|
|
|
592 |
xhr.setRequestHeader('X-EBAY-API-VERSION', configeBayShoppingVersion);
|
|
|
593 |
xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'GetMultipleItems');
|
|
|
594 |
xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
|
|
|
595 |
xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
|
|
|
596 |
xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
|
|
|
597 |
xhr.setRequestHeader('X-EBAY-API-REQUEST-ENCODING', 'XML');
|
|
|
598 |
xhr.setRequestHeader('X-Proxy-URL', configeBayShopping);
|
|
|
599 |
|
|
|
600 |
xml = xw.flush();
|
|
|
601 |
xw.close();
|
|
|
602 |
|
|
|
603 |
xhr.onload = function() {
|
19 |
- |
604 |
var jsonObj = XMLparse(xhr.responseXML, false);
|
|
|
605 |
var obj = jsonObj.GetMultipleItemsResponse;
|
2 |
- |
606 |
var returnCode = obj.Ack;
|
19 |
- |
607 |
var str;
|
2 |
- |
608 |
|
|
|
609 |
var x = document.getElementById("results");
|
|
|
610 |
|
|
|
611 |
if (returnCode == 'Success') {
|
|
|
612 |
for (i = 0; i < obj.Item.length; i++) {
|
|
|
613 |
var ItemID = getJsonValue(obj.Item[i].ItemID);
|
|
|
614 |
var HitCount = getJsonValue(obj.Item[i].HitCount);
|
|
|
615 |
|
|
|
616 |
document.getElementById('Views' + ItemID).innerHTML = HitCount;
|
|
|
617 |
}
|
|
|
618 |
} else {
|
|
|
619 |
x.className += " process-errors";
|
30 |
- |
620 |
str += '<p class="text-danger"><strong>' + returnCode + ':</strong></p>';
|
2 |
- |
621 |
|
6 |
- |
622 |
var errors = getJsonArray(obj.Errors);
|
19 |
- |
623 |
str += "<p>";
|
6 |
- |
624 |
for (i = 0; i < errors.length; i++) {
|
19 |
- |
625 |
str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
|
2 |
- |
626 |
}
|
19 |
- |
627 |
str += "</p>";
|
|
|
628 |
x.innerHTML += str;
|
2 |
- |
629 |
}
|
|
|
630 |
|
|
|
631 |
--productIdsToProcess;
|
|
|
632 |
++productIdsProcessed;
|
|
|
633 |
updateProgressBar(maxProductIdsToProcess, productIdsProcessed);
|
|
|
634 |
};
|
|
|
635 |
|
|
|
636 |
xhr.send(xml);
|
|
|
637 |
}
|
|
|
638 |
|
|
|
639 |
function priceProductIds() {
|
|
|
640 |
var i;
|
|
|
641 |
var price;
|
|
|
642 |
var lowest;
|
|
|
643 |
var difference;
|
|
|
644 |
var percentage;
|
|
|
645 |
var noPricedLower;
|
|
|
646 |
var noActive;
|
|
|
647 |
var noBetterCondition;
|
|
|
648 |
var percLower;
|
|
|
649 |
var x = document.getElementById("itemTable");
|
|
|
650 |
|
|
|
651 |
initProgressBar('Retrieving Prices (3/3)');
|
|
|
652 |
|
|
|
653 |
productsToPrice = 0;
|
|
|
654 |
maxProductsToPrice = 0;
|
|
|
655 |
productsPriced = 0;
|
|
|
656 |
|
|
|
657 |
for (i = 1; i < x.rows.length; i++) {
|
4 |
- |
658 |
if (x.rows[i].cells[4].innerText.length > 0) {
|
|
|
659 |
++productsToPrice;
|
|
|
660 |
++maxProductsToPrice;
|
180 |
- |
661 |
productPricesCount = [];
|
4 |
- |
662 |
findProductPrices(x.rows[i].cells[4].innerText, 1);
|
|
|
663 |
}
|
2 |
- |
664 |
}
|
|
|
665 |
|
|
|
666 |
function checkProductsToPrice() {
|
|
|
667 |
if (productsToPrice > 0) {
|
|
|
668 |
window.setTimeout(checkProductsToPrice, 100); // wait 100 milliseconds
|
|
|
669 |
} else {
|
|
|
670 |
/*
|
|
|
671 |
xxxxx
|
|
|
672 |
Minimum of 5 comparison listings
|
|
|
673 |
(Take out lowest and highest price before calculating the average)
|
|
|
674 |
(Don't go under $4.98)
|
|
|
675 |
(Price items below cheapest item with better condition)
|
|
|
676 |
Price within the first 20-25% listing (by number)
|
|
|
677 |
(Price below the average price)
|
|
|
678 |
adjust BIN (buy it now) when changing the price: No BIN under $10; minimum accepted 65%, auto-accepted 85+%
|
|
|
679 |
(disregard certain sellers (for now decluttr and zuber, list could be expanded))
|
|
|
680 |
*/
|
|
|
681 |
for (i = (x.rows.length - 1); i > 0; i--) {
|
|
|
682 |
noPricedLower = Number(x.rows[i].cells[7].innerHTML);
|
|
|
683 |
noActive = Number(x.rows[i].cells[6].innerHTML);
|
|
|
684 |
|
|
|
685 |
if (noActive < 6) {
|
|
|
686 |
document.getElementById("itemTable").deleteRow(i);
|
|
|
687 |
continue;
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
if (noPricedLower > 0) {
|
|
|
691 |
price = Number(x.rows[i].cells[5].innerHTML.substr(1));
|
|
|
692 |
lowest = Number(x.rows[i].cells[8].innerHTML.substr(1));
|
|
|
693 |
difference = price - lowest;
|
|
|
694 |
percentage = 100.00 - (lowest / price * 100.00);
|
|
|
695 |
x.rows[i].cells[10].innerHTML = "$" + difference.toFixed(2) + " (" + percentage.toFixed(2) + "%)";
|
|
|
696 |
|
|
|
697 |
percLower = (noPricedLower / noActive) * 100.00;
|
|
|
698 |
if (noPricedLower > 24.99) {
|
|
|
699 |
x.rows[i].cells[5].style.color = "red";
|
|
|
700 |
x.rows[i].cells[7].style.color = "red";
|
|
|
701 |
} else {
|
|
|
702 |
document.getElementById("itemTable").deleteRow(i);
|
|
|
703 |
continue;
|
|
|
704 |
}
|
|
|
705 |
|
|
|
706 |
if (difference < configDifference || percentage < configPercentage || price < configAbsoluteMinPrice) {
|
|
|
707 |
document.getElementById("itemTable").deleteRow(i);
|
|
|
708 |
continue;
|
|
|
709 |
} else {
|
|
|
710 |
x.rows[i].cells[5].style.color = "red";
|
|
|
711 |
x.rows[i].cells[10].style.color = "red";
|
|
|
712 |
}
|
|
|
713 |
} else if (noPricedLower === 0) {
|
|
|
714 |
noBetterCondition = Number(x.rows[i].cells[14].innerHTML);
|
|
|
715 |
if (noActive == (noBetterCondition + 1)) {
|
|
|
716 |
document.getElementById("itemTable").deleteRow(i);
|
|
|
717 |
continue;
|
|
|
718 |
}
|
|
|
719 |
|
|
|
720 |
price = Number(x.rows[i].cells[5].innerHTML.substr(1));
|
|
|
721 |
lowest = Number(x.rows[i].cells[8].innerHTML.substr(1));
|
|
|
722 |
difference = price - lowest;
|
|
|
723 |
percentage = 100.00 - (lowest / price * 100.00);
|
|
|
724 |
x.rows[i].cells[10].innerHTML = "$" + difference.toFixed(2) + " (" + percentage.toFixed(2) + "%)";
|
|
|
725 |
|
|
|
726 |
if ((difference * -1.00) < configDifference && (percentage * -1.00) < configPercentage) {
|
|
|
727 |
document.getElementById("itemTable").deleteRow(i);
|
|
|
728 |
continue;
|
|
|
729 |
} else {
|
|
|
730 |
x.rows[i].cells[5].style.color = "green";
|
|
|
731 |
x.rows[i].cells[10].style.color = "green";
|
|
|
732 |
}
|
|
|
733 |
continue;
|
|
|
734 |
}
|
|
|
735 |
}
|
|
|
736 |
|
|
|
737 |
endProgressBar();
|
|
|
738 |
|
|
|
739 |
x = document.getElementById("results");
|
|
|
740 |
x.innerHTML += '<p><strong>Sorting Report.....</strong></p>';
|
|
|
741 |
|
|
|
742 |
sortTableDesc("itemTable", 6);
|
|
|
743 |
|
|
|
744 |
x.innerHTML += '<p><strong>Report Finished!</strong></p>';
|
|
|
745 |
if (!x.className.includes("process-errors")) {
|
|
|
746 |
setTimeout(function() {
|
|
|
747 |
x.className = x.className.replace(" w3-show", "");
|
|
|
748 |
}, 3000);
|
|
|
749 |
}
|
|
|
750 |
}
|
|
|
751 |
}
|
|
|
752 |
|
|
|
753 |
checkProductsToPrice();
|
|
|
754 |
}
|
|
|
755 |
|
|
|
756 |
function findProductPrices(productId, pageNumber) {
|
|
|
757 |
var n = productId.indexOf(" ");
|
|
|
758 |
var productIdType = productId.substr(0, n);
|
4 |
- |
759 |
var keyword = productId.substr(n + 1);
|
2 |
- |
760 |
|
180 |
- |
761 |
var idx = (Number(keyword) * 10) + pageNumber;
|
|
|
762 |
if (productPricesCount[idx] === undefined) {
|
|
|
763 |
productPricesCount[idx] = 1;
|
|
|
764 |
} else {
|
|
|
765 |
++productPricesCount[idx];
|
|
|
766 |
}
|
|
|
767 |
|
2 |
- |
768 |
url = configeBayFinding + "?";
|
|
|
769 |
if (productIdType == 'ReferenceID') {
|
|
|
770 |
url += "OPERATION-NAME=findItemsByProduct";
|
|
|
771 |
} else {
|
|
|
772 |
url += "OPERATION-NAME=findItemsAdvanced";
|
|
|
773 |
}
|
|
|
774 |
url += "&RESPONSE-DATA-FORMAT=JSON";
|
|
|
775 |
url += "&SECURITY-APPNAME=" + configAppid;
|
|
|
776 |
url += "&SERVICE-VERSION=" + configeBayFindingVersion;
|
|
|
777 |
url += "&GLOBAL-ID=EBAY-US";
|
|
|
778 |
url += "&buyerPostalCode=";
|
|
|
779 |
url += configZip;
|
|
|
780 |
url += "&paginationInput.entriesPerPage=100";
|
|
|
781 |
url += "&paginationInput.pageNumber=";
|
|
|
782 |
url += pageNumber;
|
|
|
783 |
|
|
|
784 |
if (productIdType == 'ReferenceID') {
|
|
|
785 |
url += "&productId.@type=";
|
|
|
786 |
url += productIdType;
|
|
|
787 |
url += "&productId=";
|
4 |
- |
788 |
url += keyword;
|
2 |
- |
789 |
} else {
|
|
|
790 |
url += "&keywords=";
|
4 |
- |
791 |
url += keyword;
|
2 |
- |
792 |
}
|
|
|
793 |
|
|
|
794 |
url += "&itemFilter(0).name=ExcludeSeller";
|
|
|
795 |
url += "&itemFilter(0).value=";
|
|
|
796 |
url += configeBaySellerName;
|
|
|
797 |
|
|
|
798 |
var xhttp = new XMLHttpRequest();
|
|
|
799 |
|
|
|
800 |
xhttp.onreadystatechange = function() {
|
|
|
801 |
if (this.readyState == 4) {
|
180 |
- |
802 |
if (this.status == 200) {
|
|
|
803 |
_cb_findProductPrices(JSON.parse(this.responseText));
|
|
|
804 |
} else {
|
|
|
805 |
if (productPricesCount[idx] <= 5) {
|
|
|
806 |
window.setTimeout(function(){findProductPrices(productId, pageNumber);}, 5000);
|
|
|
807 |
} else {
|
|
|
808 |
--productsToPrice;
|
|
|
809 |
++productsPriced;
|
|
|
810 |
updateProgressBar(maxProductsToPrice, productsPriced);
|
|
|
811 |
}
|
|
|
812 |
}
|
|
|
813 |
|
2 |
- |
814 |
}
|
|
|
815 |
};
|
|
|
816 |
|
|
|
817 |
xhttp.open("GET", configProxyUrl, true);
|
|
|
818 |
xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
|
|
|
819 |
xhttp.send();
|
6 |
- |
820 |
|
2 |
- |
821 |
}
|
|
|
822 |
|
|
|
823 |
function _cb_findProductPrices(root) {
|
|
|
824 |
var array;
|
|
|
825 |
var response;
|
|
|
826 |
var ack;
|
|
|
827 |
var productId;
|
|
|
828 |
var i;
|
|
|
829 |
var currentPrice;
|
|
|
830 |
var Title = "";
|
|
|
831 |
var noLower;
|
|
|
832 |
var noActive;
|
|
|
833 |
var minPrice;
|
|
|
834 |
var maxPrice;
|
|
|
835 |
var conditionId;
|
|
|
836 |
var currentConditionId;
|
|
|
837 |
var noBetterCondition;
|
|
|
838 |
var myPrice;
|
|
|
839 |
var currentPriceInt;
|
|
|
840 |
var minBetterCondition;
|
|
|
841 |
var betterConditionbBreakdown = [];
|
|
|
842 |
var sameConditionbBreakdown = [];
|
|
|
843 |
|
|
|
844 |
if (root.findItemsAdvancedResponse !== undefined) {
|
|
|
845 |
response = root.findItemsAdvancedResponse[0];
|
|
|
846 |
} else if (root.findItemsByProductResponse !== undefined) {
|
|
|
847 |
response = root.findItemsByProductResponse[0];
|
|
|
848 |
} else {
|
|
|
849 |
--productsToPrice;
|
|
|
850 |
++productsPriced;
|
|
|
851 |
updateProgressBar(maxProductsToPrice, productsPriced);
|
|
|
852 |
return;
|
|
|
853 |
}
|
|
|
854 |
|
|
|
855 |
ack = response.ack;
|
|
|
856 |
if (ack != 'Success') {
|
4 |
- |
857 |
printeBayAPIError('Get Prices', response);
|
2 |
- |
858 |
|
|
|
859 |
if (ack == 'Failure' || ack == 'PartialFailure') {
|
|
|
860 |
--productsToPrice;
|
|
|
861 |
++productsPriced;
|
|
|
862 |
updateProgressBar(maxProductsToPrice, productsPriced);
|
|
|
863 |
return;
|
|
|
864 |
}
|
|
|
865 |
}
|
|
|
866 |
|
|
|
867 |
if (root.findItemsAdvancedResponse !== undefined) {
|
|
|
868 |
array = typeof root.findItemsAdvancedResponse[0] != 'object' ? JSON.parse(root.findItemsAdvancedResponse[0]) : root.findItemsAdvancedResponse[0].searchResult[0].item;
|
|
|
869 |
response = root.findItemsAdvancedResponse[0];
|
|
|
870 |
url = new URL(response.itemSearchURL);
|
|
|
871 |
productId = url.searchParams.get("_nkw");
|
|
|
872 |
} else {
|
|
|
873 |
array = typeof root.findItemsByProductResponse[0] != 'object' ? JSON.parse(root.findItemsByProductResponse[0]) : root.findItemsByProductResponse[0].searchResult[0].item;
|
|
|
874 |
url = new URL(response.itemSearchURL);
|
|
|
875 |
productId = url.searchParams.get("_productid");
|
|
|
876 |
}
|
|
|
877 |
|
|
|
878 |
var items = response.searchResult[0].item || [];
|
|
|
879 |
noActive = Number(document.getElementById('Active' + productId).innerHTML);
|
|
|
880 |
noLower = Number(document.getElementById('Lower' + productId).innerHTML);
|
|
|
881 |
myPrice = Number(document.getElementById('Price' + productId).innerHTML.substr(1));
|
|
|
882 |
minPrice = Number(document.getElementById('Minimum' + productId).innerHTML.substr(1));
|
|
|
883 |
maxPrice = Number(document.getElementById('Maximum' + productId).innerHTML.substr(1));
|
|
|
884 |
conditionId = Number(document.getElementById('Condition' + productId).innerHTML);
|
|
|
885 |
noBetterCondition = Number(document.getElementById('BetterCondition' + productId).innerHTML);
|
|
|
886 |
minBetterCondition = Number(document.getElementById('MinBetterCondition' + productId).innerHTML);
|
|
|
887 |
betterConditionbBreakdown = JSON.parse(document.getElementById('BetterConditionBreakdown' + productId).innerHTML);
|
|
|
888 |
sameConditionbBreakdown = JSON.parse(document.getElementById('SameConditionBreakdown' + productId).innerHTML);
|
|
|
889 |
|
|
|
890 |
for (i = 0; i < items.length; i++) {
|
|
|
891 |
Title = items[i].title[0].toLowerCase();
|
|
|
892 |
if (Title.includes("disc only") > 0 ||
|
|
|
893 |
Title.includes("disk only") > 0 ||
|
|
|
894 |
Title.includes("only disc") > 0 ||
|
|
|
895 |
Title.includes("only disk") > 0 ||
|
|
|
896 |
Title.search(/dis[ck].*only/) > 0) {
|
|
|
897 |
continue; // exclude "disc only listing
|
|
|
898 |
}
|
|
|
899 |
|
|
|
900 |
currentConditionId = (items[i].condition === undefined ? 0 : Number(items[i].condition[0].conditionId));
|
|
|
901 |
currentPrice = Number(items[i].sellingStatus[0].convertedCurrentPrice[0].__value__);
|
|
|
902 |
currentPriceInt = Math.ceil(currentPrice);
|
|
|
903 |
|
|
|
904 |
if (currentConditionId > conditionId) {
|
|
|
905 |
continue; // Like for like conditions only
|
|
|
906 |
} else if (currentConditionId > conditionId) {
|
|
|
907 |
if (minBetterCondition < 0.01 || minBetterCondition > currentPrice) {
|
|
|
908 |
minBetterCondition = currentPrice;
|
|
|
909 |
}
|
|
|
910 |
|
|
|
911 |
++noBetterCondition;
|
|
|
912 |
}
|
|
|
913 |
|
|
|
914 |
if (items[i].sellingStatus[0].bidCount === 0 && items[i].listingInfo[0].convertedBuyItNowPrice !== undefined) {
|
|
|
915 |
currentPrice = Number(items[i].listingInfo[0].convertedBuyItNowPrice[0].__value__);
|
|
|
916 |
}
|
|
|
917 |
|
|
|
918 |
if (items[i].shippingInfo[0].shippingServiceCost) {
|
|
|
919 |
currentPrice += Number(items[i].shippingInfo[0].shippingServiceCost[0].__value__);
|
|
|
920 |
}
|
|
|
921 |
|
|
|
922 |
if (currentConditionId > conditionId) {
|
|
|
923 |
if (betterConditionbBreakdown[currentPriceInt] === undefined) {
|
|
|
924 |
betterConditionbBreakdown[currentPriceInt] = 0;
|
|
|
925 |
}
|
|
|
926 |
++betterConditionbBreakdown[currentPriceInt];
|
|
|
927 |
} else {
|
|
|
928 |
if (sameConditionbBreakdown[currentPriceInt] === undefined) {
|
|
|
929 |
sameConditionbBreakdown[currentPriceInt] = 0;
|
|
|
930 |
}
|
|
|
931 |
++sameConditionbBreakdown[currentPriceInt];
|
|
|
932 |
}
|
|
|
933 |
|
|
|
934 |
if (currentPrice < myPrice) {
|
|
|
935 |
++noLower;
|
|
|
936 |
}
|
|
|
937 |
|
|
|
938 |
if (minPrice < 0.01 || minPrice > currentPrice) {
|
|
|
939 |
minPrice = currentPrice;
|
|
|
940 |
}
|
|
|
941 |
|
|
|
942 |
if (maxPrice < 0.01 || maxPrice < currentPrice) {
|
|
|
943 |
maxPrice = currentPrice;
|
|
|
944 |
}
|
|
|
945 |
|
|
|
946 |
++noActive;
|
|
|
947 |
}
|
|
|
948 |
|
|
|
949 |
document.getElementById('Active' + productId).innerHTML = noActive;
|
|
|
950 |
document.getElementById('Lower' + productId).innerHTML = noLower;
|
|
|
951 |
document.getElementById('Minimum' + productId).innerHTML = '$' + minPrice.toFixed(2);
|
|
|
952 |
document.getElementById('Maximum' + productId).innerHTML = '$' + maxPrice.toFixed(2);
|
|
|
953 |
document.getElementById('BetterCondition' + productId).innerHTML = noBetterCondition;
|
|
|
954 |
document.getElementById('MinBetterCondition' + productId).innerHTML = minBetterCondition;
|
|
|
955 |
document.getElementById('BetterConditionBreakdown' + productId).innerHTML = JSON.stringify(betterConditionbBreakdown);
|
|
|
956 |
document.getElementById('SameConditionBreakdown' + productId).innerHTML = JSON.stringify(sameConditionbBreakdown);
|
|
|
957 |
|
|
|
958 |
if (Number(response.paginationOutput[0].totalPages) > Number(response.paginationOutput[0].pageNumber)) {
|
|
|
959 |
++productsToPrice;
|
|
|
960 |
++maxProductsToPrice;
|
|
|
961 |
var row = document.getElementById('Lower' + productId).parentNode.rowIndex;
|
|
|
962 |
findProductPrices(document.getElementById("itemTable").rows[row].cells[4].innerText, Number(response.paginationOutput[0].pageNumber) + 1);
|
|
|
963 |
}
|
|
|
964 |
|
|
|
965 |
--productsToPrice;
|
|
|
966 |
++productsPriced;
|
|
|
967 |
updateProgressBar(maxProductsToPrice, productsPriced);
|
|
|
968 |
}
|
|
|
969 |
|
|
|
970 |
function changePrice(itemId) {
|
|
|
971 |
var i;
|
|
|
972 |
var newPrice = parseFloat(document.getElementById('PriceAdj' + itemId).value).toFixed(2);
|
|
|
973 |
|
|
|
974 |
if (isNaN(newPrice) || newPrice < configAdjMinPrice) {
|
|
|
975 |
document.getElementById('PriceAdj' + itemId).value = '';
|
|
|
976 |
return;
|
|
|
977 |
}
|
|
|
978 |
|
|
|
979 |
document.getElementById('PriceAdj' + itemId).value = newPrice;
|
|
|
980 |
|
|
|
981 |
if (eBayAuthTokenFlag === false) {
|
|
|
982 |
return;
|
|
|
983 |
}
|
|
|
984 |
|
|
|
985 |
var xw = new XMLWriter('UTF-8', '1.0');
|
|
|
986 |
var xhr = new XMLHttpRequest();
|
|
|
987 |
|
|
|
988 |
if (!createAddXML(xw, xhr, 'ReviseItemRequest', 'ReviseItem', itemId, newPrice)) {
|
|
|
989 |
return;
|
|
|
990 |
}
|
|
|
991 |
|
|
|
992 |
xml = xw.flush();
|
|
|
993 |
xw.close();
|
|
|
994 |
|
|
|
995 |
xhr.onload = function() {
|
19 |
- |
996 |
var jsonObj = XMLparse(xhr.responseXML, false);
|
|
|
997 |
var obj = jsonObj.ReviseItemResponse;
|
2 |
- |
998 |
var returnCode = obj.Ack;
|
19 |
- |
999 |
var str = "";
|
2 |
- |
1000 |
|
|
|
1001 |
var x = document.getElementById("results");
|
|
|
1002 |
if (x.className.indexOf("w3-show") == -1) {
|
|
|
1003 |
x.className += " w3-show";
|
|
|
1004 |
}
|
|
|
1005 |
x.className = x.className.replace(" process-errors", "");
|
|
|
1006 |
|
|
|
1007 |
if (returnCode == 'Success' || (returnCode == 'Warning' && (obj.Errors.ErrorCode == '21917108' || obj.Errors.ErrorCode == '23007'))) {
|
|
|
1008 |
document.getElementById('PriceAdj' + itemId).style.color = "green";
|
|
|
1009 |
|
19 |
- |
1010 |
str = '<p><strong>' + returnCode + '</strong></p>';
|
2 |
- |
1011 |
|
|
|
1012 |
if (returnCode == 'Warning') {
|
19 |
- |
1013 |
str += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
|
2 |
- |
1014 |
x.className += " process-errors";
|
|
|
1015 |
}
|
19 |
- |
1016 |
var fees = getJsonArray(obj.Fees.Fee);
|
|
|
1017 |
str += "<p>";
|
2 |
- |
1018 |
for (i = 0; i < fees.length; i++) {
|
|
|
1019 |
if (fees[i].Fee.text !== "0.0") {
|
19 |
- |
1020 |
str += fees[i].Name + ": $" + Number(fees[i].Fee.text).toFixed(2) + "<br/>";
|
2 |
- |
1021 |
}
|
|
|
1022 |
}
|
19 |
- |
1023 |
str += "</p>";
|
2 |
- |
1024 |
|
|
|
1025 |
if (obj.DiscountReason) {
|
19 |
- |
1026 |
str += "<p>Discount Reason: " + obj.DiscountReason + "</p>";
|
2 |
- |
1027 |
}
|
|
|
1028 |
|
30 |
- |
1029 |
if (obj.ListingRecommendations !== undefined) {
|
|
|
1030 |
var recommendations = getJsonArray(obj.ListingRecommendations.Recommendation);
|
|
|
1031 |
for (i = 0; i < recommendations.length; i++) {
|
|
|
1032 |
str += decode(recommendations[i]);
|
|
|
1033 |
}
|
2 |
- |
1034 |
}
|
19 |
- |
1035 |
|
|
|
1036 |
x.innerHTML = str;
|
2 |
- |
1037 |
} else {
|
|
|
1038 |
document.getElementById('PriceAdj' + itemId).style.color = "red";
|
19 |
- |
1039 |
str = "<p><strong>" + returnCode + ":</strong></p>";
|
2 |
- |
1040 |
x.className += " process-errors";
|
|
|
1041 |
|
6 |
- |
1042 |
var errors = getJsonArray(obj.Errors);
|
19 |
- |
1043 |
str += "<p>";
|
6 |
- |
1044 |
for (i = 0; i < errors.length; i++) {
|
19 |
- |
1045 |
str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
|
2 |
- |
1046 |
}
|
19 |
- |
1047 |
str += "</p>";
|
|
|
1048 |
x.innerHTML = str;
|
2 |
- |
1049 |
}
|
|
|
1050 |
|
|
|
1051 |
if (obj.Message) {
|
|
|
1052 |
x.innerHTML += obj.Message;
|
|
|
1053 |
}
|
|
|
1054 |
|
|
|
1055 |
if (!x.className.includes("process-errors")) {
|
|
|
1056 |
setTimeout(function() {
|
|
|
1057 |
x.className = x.className.replace(" w3-show", "");
|
|
|
1058 |
}, 3000);
|
|
|
1059 |
}
|
|
|
1060 |
};
|
|
|
1061 |
|
|
|
1062 |
xhr.send(xml);
|
|
|
1063 |
}
|
|
|
1064 |
|
|
|
1065 |
function createAddXML(xw, xhr, xmlrequest, callname, itemId, newPrice) {
|
|
|
1066 |
xw.writeStartDocument();
|
|
|
1067 |
xw.writeStartElement(xmlrequest);
|
|
|
1068 |
xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
|
|
|
1069 |
|
|
|
1070 |
xw.writeStartElement('RequesterCredentials');
|
|
|
1071 |
xw.writeElementString('eBayAuthToken', eBayAuthToken);
|
|
|
1072 |
xw.writeEndElement(); /* RequesterCredentials */
|
|
|
1073 |
|
|
|
1074 |
xw.writeStartElement('Item');
|
|
|
1075 |
|
|
|
1076 |
xw.writeStartElement('StartPrice');
|
|
|
1077 |
xw.writeAttributeString('currencyID', 'USD');
|
|
|
1078 |
xw.writeString(newPrice);
|
|
|
1079 |
xw.writeEndElement(); /* StartPrice */
|
|
|
1080 |
|
|
|
1081 |
//xw.writeElementString('ItemID', itemId);
|
|
|
1082 |
xw.writeString('<ItemID>' + itemId + '</ItemID>');
|
|
|
1083 |
|
|
|
1084 |
if (document.getElementById('BestOffer' + itemId).innerHTML == 'true') {
|
|
|
1085 |
if (newPrice >= 14.99) {
|
|
|
1086 |
var autoAcceptPrice = newPrice * configAutoAcceptPrice;
|
|
|
1087 |
var minBestOfferPrice = newPrice * configMinBestOfferPrice;
|
|
|
1088 |
|
|
|
1089 |
xw.writeStartElement('BestOfferDetails');
|
|
|
1090 |
xw.writeElementString('BestOfferEnabled', 'true');
|
|
|
1091 |
xw.writeEndElement(); /* BestOfferDetails */
|
|
|
1092 |
xw.writeStartElement('ListingDetails');
|
|
|
1093 |
xw.writeStartElement('BestOfferAutoAcceptPrice');
|
|
|
1094 |
xw.writeAttributeString('currencyID', 'USD');
|
|
|
1095 |
xw.writeString(autoAcceptPrice.toFixed(2));
|
|
|
1096 |
xw.writeEndElement(); /* BestOfferAutoAcceptPrice */
|
|
|
1097 |
xw.writeStartElement('MinimumBestOfferPrice');
|
|
|
1098 |
xw.writeAttributeString('currencyID', 'USD');
|
|
|
1099 |
xw.writeString(minBestOfferPrice.toFixed(2));
|
|
|
1100 |
xw.writeEndElement(); /* MinimumBestOfferPrice */
|
|
|
1101 |
xw.writeEndElement(); /* ListingDetails */
|
|
|
1102 |
} else {
|
|
|
1103 |
xw.writeStartElement('BestOfferDetails');
|
|
|
1104 |
xw.writeElementString('BestOfferEnabled', 'false');
|
|
|
1105 |
xw.writeEndElement(); /* BestOfferDetails */
|
|
|
1106 |
}
|
|
|
1107 |
}
|
|
|
1108 |
|
|
|
1109 |
xw.writeEndElement(); /* Item */
|
|
|
1110 |
|
|
|
1111 |
xw.writeElementString('ErrorLanguage', 'en_US');
|
|
|
1112 |
xw.writeElementString('Version', configeBayTradingVersion);
|
|
|
1113 |
xw.writeElementString('WarningLevel', configWarningLevel);
|
|
|
1114 |
|
|
|
1115 |
xw.writeEndElement(); /* xmlrequest */
|
|
|
1116 |
xw.writeEndDocument();
|
|
|
1117 |
|
|
|
1118 |
xhr.open('POST', configProxyUrl, true);
|
|
|
1119 |
xhr.setRequestHeader('Content-Type', 'text/xml');
|
|
|
1120 |
xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
|
|
|
1121 |
xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
|
|
|
1122 |
xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
|
|
|
1123 |
xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
|
|
|
1124 |
xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
|
|
|
1125 |
xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
|
|
|
1126 |
xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
|
|
|
1127 |
|
|
|
1128 |
return true;
|
|
|
1129 |
}
|
|
|
1130 |
|
|
|
1131 |
function connected() {
|
|
|
1132 |
var x;
|
|
|
1133 |
|
|
|
1134 |
eBayAuthTokenFlag = true;
|
|
|
1135 |
document.getElementById("connected").innerHTML += " (Connected)";
|
|
|
1136 |
|
|
|
1137 |
x = document.getElementById("login");
|
|
|
1138 |
x.className = x.className.replace(" w3-show", "");
|
|
|
1139 |
|
|
|
1140 |
x = document.getElementById("results");
|
|
|
1141 |
x.innerHTML = "";
|
|
|
1142 |
x.className = x.className.replace(" w3-show", "");
|
|
|
1143 |
}
|
|
|
1144 |
|
|
|
1145 |
</script>
|
17 |
- |
1146 |
<script>includeHTML();</script>
|
2 |
- |
1147 |
|
|
|
1148 |
</body>
|
|
|
1149 |
</html>
|