Subversion Repositories munaweb

Rev

Rev 147 | Rev 163 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
<!DOCTYPE html>
2
<html lang="en">
3
 
4
<head>
5
    <title>Export eBay Listings to Shopify</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/tablesorter.theme.blue.css">
21
    <script src="js/jquery.tablesorter.min.js"></script>
22
    <script src="js/jquery.tablesorter.widgets.js"></script>
23
    <script src="js/jquery.parser-input-select.js"></script>
30 - 24
    <link rel="stylesheet" href="css/style.css">
25
    <script src="js/muna-tools.js"></script>
32 - 26
    <script src="js/stopcock.js"></script>
2 - 27
</head>
28
 
29
<body onload="return initConfig();">
30 - 30
    <div>
68 - 31
        <div>
30 - 32
            <div class="container-fluid bg-secondary">
33
                <div class="clearfix">
34
                    <img class="img-fluid float-right" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" />
35
                    <h1 id="connected">Export eBay Listings to Shopify
36
                    <input id="login" type="button" class="btn bg-success mb-2 w3-hide" onclick="eBayLogin();" value="Login" /></h1>
37
                </div>
2 - 38
            </div>
39
 
30 - 40
            <div class="col border">
2 - 41
                <div>
30 - 42
                    <form id="searchForm" class="container-fluid bg-light" onsubmit="return getListings();">
43
                        <div id="form1div" class="w3-hide">
44
                            <div class="form-check">
45
                                <label for="completedList">
46
                                    <input id="completedList" class="form-check-input" type="radio" name="rptType" value="completedList" checked>Completed Listings
47
                                </label>
48
                            </div>
49
                            <div class="form-check">
50
                                <label for="liveList">
51
                                    <input id="liveList" class="form-check-input" type="radio" name="rptType" value="liveList" checked>Live Listings
52
                                </label>
53
                            </div>
54
                            <input id="startButton" type="button" class="btn btn-danger" onclick="getListings();" value="Start" />
6 - 55
                        </div>
30 - 56
                        <div id="form2div" class="w3-hide">
57
                            <input id="downloadButton" type="button" class="btn btn-dark" onclick="downloadListings()" value="Download CSV" />
6 - 58
                        </div>
2 - 59
                    </form>
60
                </div>
30 - 61
                <div class="modal" id="progressBarDiv">
62
                    <div class="modal-dialog">
63
                        <div class="modal-content">
64
                            <div class="modal-header">
65
                                <h4 id="progressBarHeader"></h4>
66
                            </div>
67
                            <div class="modal-body">
68
                                <div class="progress">
69
                                    <div id="progressBar" class="progress-bar" style="width:0%">0%</div>
70
                                </div>
71
                            </div>
72
                        </div>
2 - 73
                    </div>
74
                </div>
30 - 75
                <div id="results" class="border bg-info w3-hide"></div>
76
                <div id="csv" class="w3-hide"></div>
77
                <div id="logging"></div>
2 - 78
            </div>
79
        </div>
80
 
30 - 81
        <footer class="container-fluid text-center border border-bottom-0 border-left-0 border-right-0">
17 - 82
            <div w3-include-html="php/footer.php"></div>
2 - 83
        </footer>
84
 
85
    </div>
86
 
87
    <script>
88
 
89
// Globals
90
var tableName = 'exportTable';
91
var tableSorterName = 'selectTable';
92
var liveListing;
93
var maxPagesToProcess = 0;
94
var pagesToProcess = 0;
95
var pagesProcessed = 0;
96
var maxNotesToAdd = 0;
97
var notesToAdd = 0;
98
var notesAdded = 0;
32 - 99
var listingsToFill = 0;
100
var maxListingsToFill = 0;
101
var listingsFilled = 0;
102
var listingsToFind = 0;
103
var maxListingsToFind = 0;
104
var listingsFound = 0;
2 - 105
var html = [];
106
 
107
// Initialize Configuration Variables
108
function initConfig() {
109
    var x = document.getElementById("form1div");
110
    if (x.className.indexOf("w3-show") == -1) {
111
        x.className += " w3-show";
112
    }
113
 
114
    eBayAuthToken = readCookie();
115
    if (eBayAuthToken.length > 0) {
116
        connected();
117
    }
118
 
119
    if (eBayAuthTokenFlag === false) {
120
        x = document.getElementById("login");
121
        if (x.className.indexOf("w3-show") == -1) {
122
            x.className += " w3-show";
123
        }
124
    }
125
}
126
 
127
function connected() {
128
    var x;
129
 
130
    eBayAuthTokenFlag = true;
131
    document.getElementById("connected").innerHTML += " (Connected)";
132
 
133
    x = document.getElementById("startButton");
30 - 134
    x.className = x.className.replace(" btn-danger", " btn-dark");
2 - 135
 
136
    x = document.getElementById("login");
137
    x.className = x.className.replace(" w3-show", "");
138
 
139
    x = document.getElementById("results");
140
    x.innerHTML = "";
141
    x.className = x.className.replace(" w3-show", "");
142
    x.className = x.className.replace(" process-errors", "");
143
}
144
 
145
function requireNewLogin() {
146
    var x = document.getElementById("startButton");
30 - 147
    x.className = x.className.replace(" btn-dark", " btn-danger ");
2 - 148
}
149
 
150
function downloadListings() {
151
    var noteList = [];
152
    var table = document.getElementById(tableSorterName);
153
 
154
    maxPagesToProcess = 0;
155
    pagesToProcess = 0;
156
    pagesProcessed = 0;
157
 
158
    initProgressBar("Downloading Selected Items");
159
 
160
    var x = document.getElementById("results");
161
    x.innerHTML = '';
162
    x.className = x.className.replace("process-errors", "");
163
    if (x.className.indexOf("w3-show") == -1) {
164
        x.className += " w3-show";
165
    }
166
    x.innerHTML = '<p><strong>Downloading Listings...</strong></p>';
167
 
168
    document.getElementById("csv").innerHTML = '';
169
 
170
    tableStart();
171
    for (var i = 2; i < table.rows.length; i++) {
172
        if (table.rows[i].cells[0].children[0].checked) {
173
            ++maxPagesToProcess;
174
            ++pagesToProcess;
175
            noteList.push(table.rows[i].cells[3].innerHTML);
32 - 176
            eBaySearch(table.rows[i].cells[3].innerHTML, (table.rows[i].cells[13].innerHTML == 'Yes' ? true : false));
2 - 177
 
178
            table.deleteRow(i--);
179
        }
180
    }
181
 
182
    function checkpagesToProcess() {
183
        if (pagesToProcess > 0) {
184
            window.setTimeout(checkpagesToProcess, 100); // wait 100 milliseconds
185
        } else {
186
            tableEnd();
7 - 187
            tableSorterUpdateCounters(tableSorterName);
2 - 188
            endProgressBar();
36 - 189
            exportTableToCSV(tableName, 'import.csv', true);
2 - 190
            addNotes(noteList);
191
        }
192
    }
193
 
194
    checkpagesToProcess();
195
}
196
 
197
function addNotes(noteList) {
198
    var i, x;
199
 
200
    maxNotesToAdd = 0;
201
    notesToAdd = 0;
202
    notesAdded = 0;
203
 
204
    if (!liveListing) {
205
        initProgressBar('Adding Notes to Ended Listings');
206
 
207
        for (i = 0; i < noteList.length; i++) {
208
            ++maxNotesToAdd;
209
            ++notesToAdd;
210
            addNote(noteList[i]);
211
        }
212
    }
213
 
214
    function checkNotesToAdd() {
215
        if (notesToAdd > 0) {
216
            window.setTimeout(checkNotesToAdd, 100); // wait 100 milliseconds
217
        } else {
218
            endProgressBar();
219
 
220
            x = document.getElementById("results");
221
            x.innerHTML += '<p><strong>Report Finished!</strong></p>';
222
            if (!x.className.includes("process-errors")) {
223
                setTimeout(function() {
224
                    x.className = x.className.replace(" w3-show", "");
225
                }, 3000);
226
            }
227
        }
228
    }
229
 
230
    checkNotesToAdd();
231
}
232
 
233
function tableStart() {
234
    document.getElementById("csv").innerHTML = '';
235
    html = [];
236
 
237
    html.push('<h3>Shopify Import</h3>');
30 - 238
    html.push('<div class="border table-responsive">');
2 - 239
    html.push('<table id="' + tableName + '">');
240
    html.push('<thead>');
241
    html.push('<tr>');
242
 
243
    html.push(tableHeader('Handle'));
244
    html.push(tableHeader('Title'));
245
    html.push(tableHeader('Body (HTML)'));
246
    html.push(tableHeader('Vendor'));
247
    html.push(tableHeader('Type'));
248
    html.push(tableHeader('Tags'));
249
    html.push(tableHeader('Published'));
25 - 250
    html.push(tableHeader('Option1 Name'));
251
    html.push(tableHeader('Option1 Value'));
252
    html.push(tableHeader('Option2 Name'));
253
    html.push(tableHeader('Option2 Value'));
254
    html.push(tableHeader('Option3 Name'));
255
    html.push(tableHeader('Option3 Value'));
2 - 256
    html.push(tableHeader('Variant SKU'));
25 - 257
    html.push(tableHeader('Variant Grams'));
2 - 258
    html.push(tableHeader('Variant Inventory Tracker'));
25 - 259
    html.push(tableHeader('Variant Inventory Qty'));
2 - 260
    html.push(tableHeader('Variant Inventory Policy'));
261
    html.push(tableHeader('Variant Fulfillment Service'));
262
    html.push(tableHeader('Variant Price'));
25 - 263
    html.push(tableHeader('Variant Compare At Price'));
2 - 264
    html.push(tableHeader('Variant Requires Shipping'));
265
    html.push(tableHeader('Variant Taxable'));
266
    html.push(tableHeader('Variant Barcode'));
267
    html.push(tableHeader('Image Src'));
268
    html.push(tableHeader('Image Position'));
269
    html.push(tableHeader('Image Alt Text'));
25 - 270
    html.push(tableHeader('Gift Card'));
271
    html.push(tableHeader('Google Shopping / MPN'));
272
    html.push(tableHeader('Google Shopping / Age Group'));
273
    html.push(tableHeader('Google Shopping / Gender'));
274
    html.push(tableHeader('Google Shopping / Google Product Category'));
275
    html.push(tableHeader('SEO Title'));
276
    html.push(tableHeader('SEO Description'));
277
    html.push(tableHeader('Google Shopping / AdWords Grouping'));
278
    html.push(tableHeader('Google Shopping / AdWords Labels'));
279
    html.push(tableHeader('Google Shopping / Condition'));
280
    html.push(tableHeader('Google Shopping / Custom Product'));
281
    html.push(tableHeader('Google Shopping / Custom Label 0'));
282
    html.push(tableHeader('Google Shopping / Custom Label 1'));
283
    html.push(tableHeader('Google Shopping / Custom Label 2'));
284
    html.push(tableHeader('Google Shopping / Custom Label 3'));
285
    html.push(tableHeader('Google Shopping / Custom Label 4'));
286
    html.push(tableHeader('Variant Image'));
2 - 287
    html.push(tableHeader('Variant Weight Unit'));
25 - 288
    html.push(tableHeader('Variant Tax Code'));
289
    html.push(tableHeader('Cost per item'));
2 - 290
 
291
    html.push('</tr>');
292
    html.push('</thead>');
293
    html.push('<tbody>');
294
}
295
 
32 - 296
function tableEntry(JsonObj, onShopify) {
2 - 297
    var i, n, barcode, handle;
298
    var tags = [];
299
    var ConditionDescription = JsonObj.ConditionDescription;
300
    var ConditionID = JsonObj.ConditionID;
301
    var CurrentPrice = JsonObj.SellingStatus.CurrentPrice;
302
    var CurrentPriceValue = CurrentPrice === undefined ? 0.00 : Number(CurrentPrice.text);
303
    var price = CurrentPriceValue;
304
    var Description = JsonObj.Description;
305
    var userDescription;
306
    var ItemID = JsonObj.ItemID;
307
    var ItemSpecifics = JsonObj.ItemSpecifics;
6 - 308
    var PictureURL = getJsonArray(JsonObj.PictureDetails.PictureURL);
2 - 309
    var PrimaryCategoryName = JsonObj.PrimaryCategory.CategoryName;
16 - 310
    var Quantity = Number(JsonObj.Quantity);
311
    var QuantitySold = Number(JsonObj.SellingStatus.QuantitySold);
2 - 312
    var SKU = JsonObj.SKU;
313
    var ProductListingDetails = JsonObj.ProductListingDetails;
314
    var weightInGrams = 0;
315
    var categoryName = PrimaryCategoryName;
316
    var Title = JsonObj.Title;
317
 
318
    if (Number(ConditionID) === 1000) {
319
        tags.push("Condition: Brand New");
320
    } else {
321
        tags.push("Condition: Preowned");
322
    }
323
 
324
    n = (SKU === undefined ? 0 : SKU.indexOf(" - "));
325
    if (n > 0) {
326
        barcode = SKU.substr(n + 3);
327
        barcode = barcode.substr(barcode.indexOf(" ") + 1);
328
        handle = 'B' + barcode;
329
        barcode = '\'' + barcode;
330
        SKU = SKU.substr(0, n);
331
    } else {
332
        if (categoryName.indexOf("Books") != -1 && ProductListingDetails && ProductListingDetails.ISBN && isNumeric(ProductListingDetails.ISBN)) {
333
            barcode = '\'' + ProductListingDetails.ISBN;
334
            handle = 'B' + ProductListingDetails.ISBN;
335
        } else if (ProductListingDetails && ProductListingDetails.UPC && isNumeric(ProductListingDetails.UPC)) {
336
            barcode = '\'' + ProductListingDetails.UPC;
337
            handle = 'B' + ProductListingDetails.UPC;
338
        } else if (ProductListingDetails && ProductListingDetails.ProductReferenceID && isNumeric(ProductListingDetails.ProductReferenceID)) {
339
            barcode = 'R' + ProductListingDetails.ProductReferenceID;
340
            handle = barcode;
341
        } else {
342
            barcode = 'H' + Title.hashCode();
343
            handle = barcode;
344
        }
345
    }
346
 
347
    userDescription = extractDescription(Description);
16 - 348
    if (ItemSpecifics && ItemSpecifics.NameValueList && PrimaryCategoryName.indexOf('DVD') < 0) {
349
        userDescription += '<table><tbody>';
350
        for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
351
            var itemSpecific = ItemSpecifics.NameValueList[i];
352
            if (itemSpecific.Name != 'All returns accepted' &&
353
                itemSpecific.Name != 'Item must be returned within' &&
354
                itemSpecific.Name != 'Refund will be given as' &&
355
                itemSpecific.Name != 'Return policy details' &&
356
                itemSpecific.Name != 'Restocking Fee' &&
357
                itemSpecific.Name != 'Return shipping will be paid by') {
358
                userDescription += '<tr><td style="padding: 0;">' + itemSpecific.Name + ':</td><td style="padding: 0;">' + itemSpecific.Value + '</td></tr>';
2 - 359
            }
360
        }
16 - 361
        userDescription += '</tbody></table>';
2 - 362
    }
363
 
364
    if (ConditionDescription &&
365
        (userDescription.indexOf('Please view all actual images.') < 0 && userDescription.indexOf('mint condition') < 0)) {
366
        userDescription += '<p>' + ConditionDescription + '</p>';
367
    }
368
 
369
    if (categoryName.indexOf("CDs") != -1) {
370
        categoryName = 'Music CDs';
371
        price = 4.95;
372
    } else if (categoryName.indexOf("Movies") != -1) {
373
        categoryName = 'Movies';
374
        price = 4.95;
375
    } else if (categoryName.indexOf("Books") != -1) {
376
        categoryName = 'Books';
377
        price = 5.95;
378
    } else if (categoryName.indexOf("Trading Cards") != -1) {
379
        if (categoryName.indexOf("Baseball") != -1) {
380
            tags.push('Trading Cards: Baseball');
381
        } else if (categoryName.indexOf("Football") != -1) {
382
            tags.push('Trading Cards: Football');
383
        } else if (categoryName.indexOf("Basketball") != -1) {
384
            tags.push('Trading Cards: Basketball');
385
        } else if (categoryName.indexOf("Soccer") != -1) {
386
            tags.push('Trading Cards: Soccer');
387
        } else if (categoryName.indexOf("Ice Hockey") != -1) {
388
            tags.push('Trading Cards: Ice Hockey');
389
        } else if (categoryName.indexOf("Auto Racing") != -1) {
390
            tags.push('Trading Cards: Auto Racing');
391
        }
392
        categoryName = 'Trading Cards';
393
        price = 1.99;
394
    }
395
    tags.push(categoryName);
396
 
397
    if (liveListing) {
398
        tags.push('_eBay Live');
399
 
53 - 400
        price = round((CurrentPriceValue * 0.90), 1) + 0.05; // always end with 5
2 - 401
        if (categoryName.indexOf("CDs") != -1 && price < 4.95) {
402
            price = 4.95;
403
        } else if (categoryName.indexOf("Movies") != -1 && price < 4.95) {
404
            price = 4.95;
405
        } else if (categoryName.indexOf("Books") != -1 && price < 5.95) {
406
            price = 5.95;
407
        } else if (categoryName.indexOf("Trading Cards") != -1 && price < 1.99) {
408
            price = 1.99;
409
        }
410
    }
411
 
412
    if (JsonObj.ShippingPackageDetails !== undefined) {
413
        if (JsonObj.ShippingPackageDetails.WeightMajor !== undefined) {
414
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMajor.text) * 453.5);
415
        }
416
 
417
        if (JsonObj.ShippingPackageDetails.WeightMinor !== undefined) {
418
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMinor.text) * 28.3);
419
        }
420
    }
421
 
422
    html.push('<tr>');
423
 
424
    html.push(tableCell(handle));
425
    html.push(tableCell(Title));
426
    html.push(tableCell(escapeHtml(userDescription)));
427
    html.push(tableCell("MUNA Trading"));
428
    html.push(tableCell(categoryName));
429
    html.push(tableCell(tags.join(',')));
430
    html.push(tableCell("TRUE"));
28 - 431
    html.push(tableCell("Title"));
432
    html.push(tableCell("Default Title"));
25 - 433
    html.push(tableCell(""));
434
    html.push(tableCell(""));
435
    html.push(tableCell(""));
436
    html.push(tableCell(""));
2 - 437
    html.push(tableCell((SKU !== undefined ? SKU : "")));
25 - 438
    html.push(tableCell(Math.floor(weightInGrams)));
2 - 439
    html.push(tableCell("shopify"));
16 - 440
    html.push(tableCell((Quantity - QuantitySold)));
2 - 441
    html.push(tableCell("deny"));
442
    html.push(tableCell("manual"));
443
    html.push(tableCell(price));
25 - 444
    html.push(tableCell(""));
2 - 445
    html.push(tableCell("TRUE"));
446
    html.push(tableCell("TRUE"));
447
    html.push(tableCell(barcode));
32 - 448
    if (onShopify) {
449
        html.push(tableCell(""));
450
        html.push(tableCell(""));
451
        html.push(tableCell(""));
452
    } else {
453
        html.push(tableCell(PictureURL[0].substr(0, PictureURL[0].lastIndexOf('/') + 1) + '$_57.JPG'));
454
        html.push(tableCell(1));
455
        html.push(tableCell(Title + " Image 1"));
456
    }
25 - 457
    html.push(tableCell("FALSE"));
458
    html.push(tableCell(""));
459
    html.push(tableCell(""));
460
    html.push(tableCell(""));
461
    html.push(tableCell(""));
462
    html.push(tableCell(""));
463
    html.push(tableCell(""));
464
    html.push(tableCell(""));
465
    html.push(tableCell(""));
466
    html.push(tableCell(""));
467
    html.push(tableCell(""));
468
    html.push(tableCell(""));
469
    html.push(tableCell(""));
470
    html.push(tableCell(""));
471
    html.push(tableCell(""));
472
    html.push(tableCell(""));
473
    html.push(tableCell(""));
2 - 474
    html.push(tableCell("oz"));
25 - 475
    html.push(tableCell(""));
476
    html.push(tableCell(""));
2 - 477
 
478
    html.push('</tr>');
479
 
32 - 480
    if (!onShopify) {
481
        for (i = 1; i < PictureURL.length; i++) {
482
            html.push('<tr>');
2 - 483
 
32 - 484
            html.push(tableCell(handle));
485
            html.push(tableCell(""));
486
            html.push(tableCell(""));
487
            html.push(tableCell(""));
488
            html.push(tableCell(""));
489
            html.push(tableCell(""));
490
            html.push(tableCell(""));
491
            html.push(tableCell(""));
492
            html.push(tableCell(""));
493
            html.push(tableCell(""));
494
            html.push(tableCell(""));
495
            html.push(tableCell(""));
496
            html.push(tableCell(""));
497
            html.push(tableCell(""));
498
            html.push(tableCell(""));
499
            html.push(tableCell(""));
500
            html.push(tableCell(""));
501
            html.push(tableCell(""));
502
            html.push(tableCell(""));
503
            html.push(tableCell(""));
504
            html.push(tableCell(""));
505
            html.push(tableCell(""));
506
            html.push(tableCell(""));
507
            html.push(tableCell(""));
508
            html.push(tableCell(PictureURL[i].substr(0, PictureURL[i].lastIndexOf('/') + 1) + '$_57.JPG'));
509
            html.push(tableCell(i + 1));
510
            html.push(tableCell(Title + " Image " + (i + 1)));
511
            html.push(tableCell(""));
512
            html.push(tableCell(""));
513
            html.push(tableCell(""));
514
            html.push(tableCell(""));
515
            html.push(tableCell(""));
516
            html.push(tableCell(""));
517
            html.push(tableCell(""));
518
            html.push(tableCell(""));
519
            html.push(tableCell(""));
520
            html.push(tableCell(""));
521
            html.push(tableCell(""));
522
            html.push(tableCell(""));
523
            html.push(tableCell(""));
524
            html.push(tableCell(""));
525
            html.push(tableCell(""));
526
            html.push(tableCell(""));
527
            html.push(tableCell(""));
528
            html.push(tableCell(""));
529
            html.push(tableCell(""));
530
            html.push(tableCell(""));
2 - 531
 
32 - 532
            html.push('</tr>');
533
        }
2 - 534
    }
535
}
536
 
537
function extractDescription(str) {
538
    var startText = "<!-- *************** Place description here ****************** -->";
539
    var startPos = str.indexOf(startText) + startText.length;
540
    var endPos = str.lastIndexOf("<!-- *************** Place description here ****************** -->");
541
    var userDescription = str.substr(startPos, endPos - startPos);
542
    var parser = new DOMParser();
543
    var htmlDoc = parser.parseFromString(userDescription, "text/html");
544
 
545
    return ((htmlDoc.getElementsByTagName('div')[0] !== undefined ? htmlDoc.getElementsByTagName('div')[0].innerHTML : userDescription));
546
}
547
 
548
function tableEnd() {
549
    html.push('</tbody>');
550
    html.push('</table>');
551
    html.push('</div>');
552
 
553
    document.getElementById("csv").innerHTML = html.join('');
554
}
555
 
556
function addNote(itemId) {
557
    var i;
558
    var xml;
559
 
560
    var xw = new XMLWriter('UTF-8', '1.0');
561
    var xhr = new XMLHttpRequest();
562
 
563
    if (!createAddXMLNote(xw, xhr, 'SetUserNotesRequest', 'SetUserNotes', itemId)) {
564
        return;
565
    }
566
 
567
    xml = xw.flush();
568
    xw.close();
569
 
570
    xhr.onload = function() {
16 - 571
        var jsonObj = XMLparse(xhr.responseXML, false);
572
        var obj = jsonObj.SetUserNotesResponse;
2 - 573
        var returnCode = obj.Ack;
19 - 574
        var str;
2 - 575
 
576
        var x = document.getElementById("results");
577
        if (x.className.indexOf("w3-show") == -1) {
578
            x.className += " w3-show";
579
        }
580
 
581
        if (returnCode == 'Success' || (returnCode == 'Warning' && obj.Errors.ErrorCode == '21917108')) {
19 - 582
            str = '<p>' + itemId + ': <strong>' + returnCode + '</strong></p>';
2 - 583
 
584
            if (returnCode == 'Warning') {
19 - 585
                str += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
2 - 586
            }
19 - 587
 
588
            x.innerHTML += str;
2 - 589
        } else {
590
            x.className += " process-errors";
30 - 591
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';
2 - 592
 
6 - 593
            var errors = getJsonArray(obj.Errors);
19 - 594
            str += "<p>";
6 - 595
            for (i = 0; i < errors.length; i++) {
19 - 596
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 597
            }
19 - 598
            str += "</p>";
599
 
600
            x.innerHTML += str;
2 - 601
        }
602
 
603
        if (obj.Message) {
604
            x.innerHTML += obj.Message;
605
        }
606
 
607
        --notesToAdd;
608
        ++notesAdded;
609
 
610
        updateProgressBar(maxNotesToAdd, notesAdded);
611
    };
612
 
613
    xhr.send(xml);
614
}
615
 
616
function createAddXMLNote(xw, xhr, xmlrequest, callname, itemId) {
617
    var today = new Date();
618
    var todayYYYYMMDD = today.toISOString().slice(0, 10);
619
 
620
    xw.writeStartDocument();
621
    xw.writeStartElement(xmlrequest);
622
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
623
 
624
    xw.writeStartElement('RequesterCredentials');
625
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
626
    xw.writeEndElement(); /* RequesterCredentials */
627
 
628
    xw.writeElementString('ItemID', itemId);
629
    xw.writeElementString('Action', 'AddOrUpdate');
630
    xw.writeElementString('NoteText', 'Exported to Shopify on ' + todayYYYYMMDD);
631
 
632
    xw.writeElementString('ErrorLanguage', 'en_US');
633
    xw.writeElementString('Version', configeBayTradingVersion);
634
    xw.writeElementString('WarningLevel', configWarningLevel);
635
 
636
    xw.writeEndElement(); /* xmlrequest */
637
    xw.writeEndDocument();
638
 
639
    xhr.open('POST', configProxyUrl, true);
640
    xhr.setRequestHeader('Content-Type', 'text/xml');
641
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
642
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
643
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
644
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
645
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
646
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
647
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
648
 
649
    return true;
650
}
651
 
32 - 652
function eBaySearch(itemId, onShopify) {
2 - 653
    var i;
654
    var xml;
655
 
656
    var xw = new XMLWriter('UTF-8', '1.0');
657
    var xhr = new XMLHttpRequest();
658
 
659
    if (!createAddXMLSearch(xw, xhr, 'GetItemRequest', 'GetItem', itemId)) {
660
        return;
661
    }
662
 
663
    xml = xw.flush();
664
    xw.close();
665
 
666
    xhr.onload = function() {
16 - 667
        var jsonObj = XMLparse(xhr.responseXML, false);
668
        var obj = jsonObj.GetItemResponse;
2 - 669
        var returnCode = obj.Ack;
19 - 670
        var str;
2 - 671
 
672
        var x = document.getElementById("results");
673
        if (x.className.indexOf("w3-show") == -1) {
674
            x.className += " w3-show";
675
        }
676
 
677
        if (returnCode == 'Success') {
32 - 678
            tableEntry(obj.Item, onShopify);
2 - 679
        } else {
680
            x.className += " process-errors";
30 - 681
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';
2 - 682
 
6 - 683
            var errors = getJsonArray(obj.Errors);
19 - 684
            str += "<p>";
6 - 685
            for (i = 0; i < errors.length; i++) {
19 - 686
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 687
            }
19 - 688
            str += "</p>";
6 - 689
 
19 - 690
            x.innerHTML += str;
2 - 691
        }
692
 
693
        --pagesToProcess;
694
        ++pagesProcessed;
695
 
696
        updateProgressBar(maxPagesToProcess, pagesProcessed);
697
    };
698
 
699
    xhr.send(xml);
700
}
701
 
702
function createAddXMLSearch(xw, xhr, xmlrequest, callname, itemId) {
703
 
704
    xw.writeStartDocument();
705
    xw.writeStartElement(xmlrequest);
706
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
707
 
708
    xw.writeStartElement('RequesterCredentials');
709
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
710
    xw.writeEndElement(); /* RequesterCredentials */
711
 
712
    xw.writeElementString('ItemID', itemId);
713
    xw.writeElementString('IncludeItemSpecifics', 'true');
714
    xw.writeElementString('DetailLevel', 'ReturnAll');
715
 
716
    xw.writeElementString('ErrorLanguage', 'en_US');
717
    xw.writeElementString('Version', configeBayTradingVersion);
718
    xw.writeElementString('WarningLevel', configWarningLevel);
719
 
720
    xw.writeEndElement(); /* xmlrequest */
721
    xw.writeEndDocument();
722
 
723
    xhr.open('POST', configProxyUrl, true);
724
    xhr.setRequestHeader('Content-Type', 'text/xml');
725
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
726
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
727
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
728
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
729
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
730
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
731
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
732
 
733
    return true;
734
}
735
 
736
function getListings() {
737
    var x;
738
 
739
    if (eBayAuthTokenFlag === false) {
740
        return;
741
    }
742
 
743
    document.getElementById("logging").innerHTML = '';
744
 
745
    x = document.getElementById("results");
746
    if (x.className.indexOf("w3-show") == -1) {
747
        x.className += " w3-show";
748
    }
749
    x.className = x.className.replace("process-errors", "");
750
    x.innerHTML = '<p><strong>Retrieving Listings...</strong></p>';
751
 
32 - 752
    initProgressBar('Getting Items for Export (Step 1/3)');
2 - 753
 
754
    liveListing = (getRadioValue('rptType') == 'liveList');
755
    tableSorterStart();
756
    maxPagesToProcess = 1;
757
    pagesToProcess = 1;
758
    pagesProcessed = 0;
759
    eBaySorterSearch(1);
760
 
761
    function checkpagesToProcess() {
762
        if (pagesToProcess > 0) {
763
            window.setTimeout(checkpagesToProcess, 100); // wait 100 milliseconds
764
        } else {
765
            tableSorterEnd();
766
            endProgressBar();
767
            // fillSorterListings(); is now in tableSorterEnd()
768
        }
769
    }
770
 
771
    checkpagesToProcess();
772
}
773
 
774
function tableSorterStart() {
775
    document.getElementById("logging").innerHTML = '';
776
    html = [];
777
 
778
    html.push('<h3>Items for Export</h3>');
779
    html.push('<p>Showing <span id="filtered-rows">0</span> of <span id="total-rows">0</span> / <span id="selected-rows">0</span> selected.</p>');
30 - 780
    html.push('<div class="border table-responsive">');
2 - 781
    html.push('<table id="' + tableSorterName + '" class="tablesorter">');
782
    html.push('<thead>');
783
    html.push('<tr>');
784
 
6 - 785
    html.push(tableHeaderCheckbox());
2 - 786
    html.push(tableHeader('Image'));
787
    html.push(tableHeader('Title'));
788
    html.push(tableHeader('Item Id'));
789
    html.push(tableHeader('SKU'));
790
    html.push(tableHeader('Category'));
791
    html.push(tableHeader('Format'));
792
    html.push(tableHeader('Price'));
793
    html.push(tableHeader('Quantity'));
794
    html.push(tableHeader('Views'));
795
    html.push(tableHeader('Watchers'));
796
    html.push(tableHeader(liveListing ? 'Start Date' : 'End Date'));
797
    html.push(tableHeader('Note'));
32 - 798
    html.push(tableHeader('Shopify'));
2 - 799
 
800
    html.push('</tr>');
801
    html.push('</thead>');
802
    html.push('<tbody>');
803
}
804
 
805
function tableSorterEntry(JsonObj) {
806
    var i;
807
    var image;
808
    var title;
809
    var itemId;
810
    var sku;
811
    var format;
812
    var price;
813
    var quantity;
814
    var views;
815
    var watchers;
816
    var listingDate;
817
    var privateNote;
818
    var ebayNote;
819
    var relisted;
16 - 820
    var bidCount;
2 - 821
 
822
    for (i = 0; i < JsonObj.length; i++) {
16 - 823
        image = getJsonValue(JsonObj[i].PictureDetails.GalleryURL).replace('http:', 'https:');
2 - 824
        title = getJsonValue(JsonObj[i].Title);
825
        itemId = getJsonValue(JsonObj[i].ItemID);
826
        sku = getJsonValue(JsonObj[i].SKU);
827
        format = getJsonValue(JsonObj[i].ListingType);
16 - 828
        bidCount = (typeof(JsonObj[i].SellingStatus) === 'object' ? Number(getJsonValue(JsonObj[i].SellingStatus.BidCount)) : 0);
2 - 829
        if (format == 'Chinese') {
830
            format = 'Auction';
831
            price = getJsonValue(JsonObj[i].StartPrice.text);
832
        } else {
833
            format = 'Fixed Price';
834
            price = getJsonValue(JsonObj[i].BuyItNowPrice.text);
835
        }
836
        quantity = getJsonValue(JsonObj[i].QuantityAvailable);
837
        views = '';
16 - 838
        watchers = Number(getJsonValue(JsonObj[i].WatchCount));
839
        listingDate = getJsonValue((liveListing ? JsonObj[i].ListingDetails.StartTime : JsonObj[i].ListingDetails.EndTime)).substr(0, 10);
2 - 840
        privateNote = getJsonValue(JsonObj[i].PrivateNotes);
841
        ebayNote = getJsonValue(JsonObj[i].eBayNotes);
842
        relisted = getJsonValue(JsonObj[i].Relisted);
843
 
844
        if (!liveListing) {
845
            if (privateNote.startsWith("Exported to ") || relisted == 'true' || privateNote.startsWith("Sold via ") || privateNote.startsWith("Relisted As New Item")) {
846
                continue;
847
            }
16 - 848
        } else {
849
            if (bidCount > 0) {
850
                continue;
851
            }
2 - 852
        }
68 - 853
 
854
        if (Number(quantity) < 1) {
855
            continue;
856
        }
2 - 857
 
858
        html.push('<tr>');
859
 
860
        html.push(tableCellCheckbox());
30 - 861
        html.push(tableCell('<img class="img-fluid" src="' + image + '" alt="Gallery Image" style="max-height:100px;max-width:100px;">'));
2 - 862
        html.push(tableCell(title));
863
        html.push(tableCell(itemId));
864
        html.push(tableCell(sku));
865
        html.push(tableCellLabel('Category' + itemId));
866
        html.push(tableCell(format));
867
        html.push(tableCell('$' + price));
868
        html.push(tableCell(quantity));
869
        html.push(tableCellLabel('Views' + itemId));
870
        html.push(tableCell(watchers));
871
        html.push(tableCell(listingDate));
872
        html.push(tableCell(privateNote + ' ' + ebayNote));
32 - 873
        html.push(tableCellLabel('Shopify' + itemId));
2 - 874
 
875
        html.push('</tr>');
876
    }
877
}
878
 
879
function tableSorterEnd() {
880
    html.push('</tbody>');
881
    html.push('</table>');
882
    html.push('</div>');
883
 
884
    document.getElementById("logging").innerHTML = html.join('');
885
 
886
    $(function() {
887
        $("#" + tableSorterName).on('tablesorter-initialized', function() {
888
 
889
            // class name to add on tr when checkbox is checked
890
            var highlightClass = 'checked',
891
                // resort the table after the checkbox is modified?
892
                resort = true,
893
                $table = $(this),
894
                c = this.config,
895
                wo = c && c.widgetOptions,
896
                // include sticky header checkbox; if installed
897
                $sticky = c && wo.$sticky || '',
898
                doChecky = function(c, col) {
899
                    $table
900
                        .children('tbody')
901
                        .children('tr:visible')
902
                        .children('td:nth-child( ' + (parseInt(col, 10) + 1) + ' )')
903
                        .find('input[type=checkbox]')
904
                        .each(function() {
905
                            this.checked = c;
906
                            $(this).trigger('change');
907
                        });
908
                };
909
 
910
            $table
911
                .children('tbody')
912
                .on('change', 'input[type=checkbox]', function() {
913
                    // ignore change if updating all rows
914
                    if ($table[0].ignoreChange) {
915
                        return;
916
                    }
917
                    var $this = $(this);
918
                    $this.closest('tr').toggleClass(highlightClass, this.checked);
19 - 919
                    // resort will jump bqack to the top
920
                    // $this.trigger('updateCell', [$this.closest('td'), resort]);
2 - 921
 
922
                    // handle header
7 - 923
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
2 - 924
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
925
                    var ua = window.navigator.userAgent;
926
                    if (checkedCount === 0) {
927
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', false);
928
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
929
                    } else if (checkedCount === rowCount) {
930
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', true);
931
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
932
                    } else {
933
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
934
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', true);
935
                    }
936
                    $('#selected-rows').html(checkedCount);
937
                })
938
                .end()
939
                .add($sticky)
940
                .find('thead input[type=checkbox]')
941
                // Click on checkbox in table header to toggle all inputs
942
                .on('change', function() {
943
                    // prevent updateCell for every cell
944
                    $table[0].ignoreChange = true;
945
                    var c = this.checked,
946
                        col = $(this).closest('th').attr('data-column');
947
                    doChecky(c, col);
948
                    // update main & sticky header
949
 
950
                    $table.children('tbody').children('tr:visible').toggleClass(highlightClass, c);
951
                    // update all at once
952
                    $table[0].ignoreChange = false;
953
                    $table.trigger('update', [resort]);
954
 
955
                    // handle header
7 - 956
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
2 - 957
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
958
                    var ua = window.navigator.userAgent;
959
                    if (checkedCount === 0) {
960
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', false);
961
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
962
                    } else if (checkedCount === rowCount) {
963
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', true);
964
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
965
                    } else {
966
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
967
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', true);
968
                    }
969
                    $('#selected-rows').html(checkedCount);
970
                })
971
                .on('mouseup', function() {
972
                    return false;
973
                });
974
 
975
        });
976
 
977
        $("#" + tableSorterName).tablesorter({
978
            theme: "blue",
979
            widgets: ["zebra", "stickyHeaders", "filter"],
980
            headers: {
981
                0: {
982
                    sorter: "checkbox"
983
                },
984
                1: {
985
                    sorter: false,
986
                    filter: false
987
                }
988
            },
989
            initialized: function() {
990
                fillSorterListings();
991
            }
992
        });
993
 
994
        $("#" + tableSorterName).bind('filterInit filterEnd', function(event, data) {
995
            $('#filtered-rows').html(data.filteredRows);
996
            $('#total-rows').html(data.totalRows);
997
        });
998
    });
999
}
1000
 
1001
function eBaySorterSearch(pageNo) {
1002
    var i;
1003
    var xml;
1004
 
1005
    var xw = new XMLWriter('UTF-8', '1.0');
1006
    var xhr = new XMLHttpRequest();
1007
 
1008
    if (!createSorterAddXMLSearch(xw, xhr, 'GetMyeBaySelling', pageNo)) {
1009
        return;
1010
    }
1011
 
1012
    xml = xw.flush();
1013
    xw.close();
1014
 
1015
    xhr.onload = function() {
16 - 1016
        var jsonObj = XMLparse(xhr.responseXML, false);
1017
        var obj = jsonObj.GetMyeBaySellingResponse;
2 - 1018
        var returnCode = obj.Ack;
19 - 1019
        var str;
2 - 1020
 
1021
        var objArray = (liveListing ? obj.ActiveList : obj.UnsoldList);
1022
 
1023
        var x = document.getElementById("results");
1024
 
1025
        if (returnCode == 'Success') {
16 - 1026
            tableSorterEntry(objArray.ItemArray.Item);
2 - 1027
 
1028
            if (Number(objArray.PaginationResult.TotalNumberOfPages) > pageNo) {
1029
                maxPagesToProcess = Number(objArray.PaginationResult.TotalNumberOfPages);
1030
                ++pagesToProcess;
1031
                eBaySorterSearch(pageNo + 1);
1032
            }
1033
 
1034
            updateProgressBar(maxPagesToProcess, pagesProcessed);
1035
        } else {
1036
            x.className += " process-errors";
30 - 1037
            str = '<p class="text-danger">' + obj.CorrelationID + ': <strong>' + returnCode + ':</strong></p>';
6 - 1038
            var errors = getJsonArray(obj.Errors);
19 - 1039
            str += "<p>";
6 - 1040
            for (i = 0; i < errors.length; i++) {
19 - 1041
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 1042
            }
19 - 1043
            str += "</p>";
6 - 1044
 
19 - 1045
            x.innerHTML += str;
2 - 1046
        }
1047
 
1048
        --pagesToProcess;
1049
        ++pagesProcessed;
1050
 
1051
        updateProgressBar(maxPagesToProcess, pagesProcessed);
1052
    };
1053
 
1054
    xhr.send(xml);
1055
}
1056
 
1057
function createSorterAddXMLSearch(xw, xhr, callname, pageNo) {
14 - 1058
    var outputSelector;
1059
 
2 - 1060
    xw.writeStartDocument();
1061
    xw.writeStartElement(callname + "Request");
1062
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
1063
 
1064
    xw.writeStartElement('RequesterCredentials');
1065
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
1066
    xw.writeEndElement(); /* RequesterCredentials */
1067
 
1068
    xw.writeElementString('DetailLevel', 'ReturnAll');
1069
    xw.writeStartElement('DeletedFromSoldList');
1070
    xw.writeElementString('Include', 'false');
1071
    xw.writeEndElement(); /* DeletedFromSoldList */
1072
    xw.writeStartElement('DeletedFromUnsoldList');
1073
    xw.writeElementString('Include', 'false');
1074
    xw.writeEndElement(); /* DeletedFromUnsoldList */
1075
    xw.writeStartElement('ScheduledList');
1076
    xw.writeElementString('Include', 'false');
1077
    xw.writeEndElement(); /* ScheduledList */
1078
    xw.writeStartElement('SellingSummary');
1079
    xw.writeElementString('Include', 'false');
1080
    xw.writeEndElement(); /* SellingSummary */
1081
    xw.writeStartElement('SoldList');
1082
    xw.writeElementString('Include', 'false');
1083
    xw.writeEndElement(); /* SoldList */
1084
 
1085
    xw.writeStartElement(liveListing ? 'UnsoldList' : 'ActiveList');
1086
    xw.writeElementString('Include', 'false');
1087
    xw.writeEndElement(); /* ActiveList */
1088
 
1089
    xw.writeStartElement(liveListing ? 'ActiveList' : 'UnsoldList');
1090
    xw.writeElementString('Include', 'true');
1091
    xw.writeElementString('IncludeNotes', 'true');
1092
    xw.writeStartElement('Pagination');
1093
    xw.writeElementString('EntriesPerPage', '200');
1094
    xw.writeElementString('PageNumber', '' + pageNo);
1095
    xw.writeEndElement(); /* Pagination*/
1096
    xw.writeEndElement(); /* UnsoldList> */
1097
 
14 - 1098
    outputSelector = liveListing ? 'ActiveList.' : 'UnsoldList.';
1099
 
16 - 1100
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SellingStatus.BidCount');
14 - 1101
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.BuyItNowPrice');
1102
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.eBayNotes');
1103
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ItemID');
16 - 1104
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingDetails.' + (liveListing ? 'StartTime' : 'EndTime'));
14 - 1105
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingType');
1106
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PrivateNotes');
1107
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.QuantityAvailable');
1108
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PictureDetails');
1109
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Relisted');
1110
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SKU');
1111
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Title');
1112
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.StartPrice');
1113
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.WatchCount');
1114
    xw.writeElementString('OutputSelector', outputSelector + 'PaginationResult');
1115
 
2 - 1116
    xw.writeElementString('ErrorLanguage', 'en_US');
1117
    xw.writeElementString('Version', configeBayTradingVersion);
1118
    xw.writeElementString('WarningLevel', configWarningLevel);
1119
 
1120
    xw.writeEndElement(); /* xmlrequest */
1121
    xw.writeEndDocument();
1122
 
1123
    xhr.open('POST', configProxyUrl, true);
1124
    xhr.setRequestHeader('Content-Type', 'text/xml');
1125
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
1126
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
1127
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
1128
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
1129
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
1130
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
1131
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
1132
 
1133
    return true;
1134
}
1135
 
1136
function fillSorterListings() {
1137
    var i;
1138
    var x = document.getElementById(tableSorterName);
1139
    var fillList = [];
1140
    var maxItems = 20;
1141
 
1142
    listingsToFill = 0;
1143
    maxListingsToFill = 0;
1144
    listingsFilled = 0;
1145
 
32 - 1146
    initProgressBar('Filling Listing Information (Step 2/3)');
2 - 1147
 
1148
    for (i = 2; i < x.rows.length; i++) {
1149
        fillList.push(x.rows[i].cells[3].innerHTML);
1150
    }
6 - 1151
 
16 - 1152
    for (i = 0; (i * maxItems) < fillList.length; i++) {
2 - 1153
        ++listingsToFill;
1154
        ++maxListingsToFill;
1155
        fillSorterListing(fillList.slice(i * maxItems, (i + 1) * maxItems));
1156
    }
1157
 
1158
    function checkListingsToFill() {
1159
        if (listingsToFill > 0) {
1160
            window.setTimeout(checkListingsToFill, 100); // wait 100 milliseconds
1161
        } else {
1162
            $("#" + tableSorterName).trigger("update");
1163
 
1164
            endProgressBar();
32 - 1165
            findOnShopify();
1166
        }
1167
    }
2 - 1168
 
32 - 1169
    checkListingsToFill();
1170
}
1171
 
1172
function findOnShopify() {
1173
    var i;
1174
    var x = document.getElementById(tableSorterName);
1175
 
1176
    listingsToFind = 0;
1177
    maxListingsToFind = 0;
1178
    listingsFound = 0;
1179
 
1180
    initProgressBar('Finding Listings already on Shopify (Step 3/3)');
1181
 
1182
    for (i = 2; i < x.rows.length; i++) {
1183
        ++listingsToFind;
1184
        ++maxListingsToFind;
54 - 1185
        findShopifyListing(x.rows[i].cells[3].innerHTML, x.rows[i].cells[2].innerText).then(function(env) {
32 - 1186
		    --listingsToFind;
1187
            ++listingsFound;
1188
            updateProgressBar(maxListingsToFind, listingsFound);
1189
        });
1190
    }
1191
 
1192
    function checkListingsToFind() {
1193
        if (listingsToFind > 0) {
1194
            window.setTimeout(checkListingsToFind, 100); // wait 100 milliseconds
1195
        } else {
1196
            $("#" + tableSorterName).trigger("update");
1197
 
1198
            endProgressBar();
1199
 
2 - 1200
            x = document.getElementById("form1div");
1201
            x.className = x.className.replace(" w3-show", "");
1202
            x = document.getElementById("form2div");
1203
            x.className += " w3-show";
1204
 
1205
            x = document.getElementById("results");
1206
            x.innerHTML += '<p><strong>Report Finished!</strong></p>';
1207
            if (!x.className.includes("process-errors")) {
1208
                setTimeout(function() {
1209
                    x.className = x.className.replace(" w3-show", "");
1210
                }, 3000);
1211
            }
1212
        }
1213
    }
1214
 
32 - 1215
    checkListingsToFind();
2 - 1216
}
1217
 
32 - 1218
const findShopifyListing = stopcock(function request(itemId, title) {
1219
	var xhttp = new XMLHttpRequest();
1220
	xhttp.onreadystatechange = function() {
1221
		if (this.readyState == 4 && this.status == 200) {
1222
			var json = JSON.parse(this.responseText);
139 - 1223
			if (typeof(json.products) != 'undefined') {
32 - 1224
			    var x = document.getElementById('Shopify' + itemId);
139 - 1225
			    x.innerHTML = (json.products.length > 0 ? 'Yes' : 'No');
32 - 1226
			}
1227
 
1228
            return Promise.resolve(true);
1229
		}
1230
	};
1231
 
53 - 1232
    title = cleanTitleForShopifySearch(title);
1233
 
32 - 1234
	xhttp.open("GET", configProxyUrl, true);
145 - 1235
	xhttp.setRequestHeader("X-Proxy-Url", configShopifyUrl + configShopifyProductsUrl + '?limit=1&title=' + title);
32 - 1236
	xhttp.setRequestHeader("X-LEAVE-ENCODED", "1");
1237
	xhttp.send();
1238
});
1239
 
2 - 1240
function fillSorterListing(itemIdList) {
1241
    var i;
1242
    var xml;
1243
 
1244
    var xw = new XMLWriter('UTF-8', '1.0');
1245
    var xhr = new XMLHttpRequest();
1246
 
1247
    if (!createSorterFillXMLSearch(xw, xhr, 'GetMultipleItems', itemIdList)) {
1248
        return;
1249
    }
1250
 
1251
    xml = xw.flush();
1252
    xw.close();
1253
 
1254
    xhr.onload = function() {
16 - 1255
        var jsonObj = XMLparse(xhr.responseXML, false);
1256
        var obj = jsonObj.GetMultipleItemsResponse;
147 - 1257
        var returnCode;
19 - 1258
        var str;
2 - 1259
        var x = document.getElementById("results");
1260
 
147 - 1261
        if (obj.Ack === undefined) {
158 - 1262
            fillSorterListing(itemIdList);
147 - 1263
        } else {
1264
            returnCode = obj.Ack;
1265
        }
1266
 
2 - 1267
        if (returnCode == 'Success') {
1268
            for (i = 0; i < obj.Item.length; i++) {
1269
                var itemId = getJsonValue(obj.Item[i].ItemID);
1270
                document.getElementById("Views" + itemId).innerHTML = getJsonValue(obj.Item[i].HitCount);
1271
                document.getElementById("Category" + itemId).innerHTML = getJsonValue(obj.Item[i].PrimaryCategoryName);
6 - 1272
            }
2 - 1273
        } else {
1274
            x.className += " process-errors";
30 - 1275
            str = '<p class="text-danger"><strong>' + returnCode + ':</strong></p>';
2 - 1276
 
6 - 1277
            var errors = getJsonArray(obj.Errors);
19 - 1278
            str += "<p>";
6 - 1279
            for (i = 0; i < errors.length; i++) {
19 - 1280
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 1281
            }
1282
            x.innerHTML += "</p>";
19 - 1283
 
1284
            x.innerHTML += str;
2 - 1285
        }
1286
 
1287
        --listingsToFill;
1288
        ++listingsFilled;
1289
        updateProgressBar(maxListingsToFill, listingsFilled);
1290
    };
1291
 
1292
    xhr.send(xml);
1293
}
1294
 
1295
function createSorterFillXMLSearch(xw, xhr, callname, itemIdList) {
1296
    var i;
6 - 1297
 
2 - 1298
    xw.writeStartDocument();
1299
    xw.writeStartElement(callname + "Request");
1300
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
1301
 
1302
    for (i = 0; i < itemIdList.length; i++) {
1303
        xw.writeElementString('ItemID', itemIdList[i]);
1304
    }
1305
 
1306
    xw.writeElementString('ErrorLanguage', 'en_US');
1307
    xw.writeElementString('Version', configeBayShoppingVersion);
1308
    xw.writeElementString('WarningLevel', configWarningLevel);
1309
 
1310
    xw.writeEndElement(); /* xmlrequest */
1311
    xw.writeEndDocument();
1312
 
1313
    xhr.open('POST', configProxyUrl, true);
1314
    xhr.setRequestHeader('Content-Type', 'text/xml');
1315
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
1316
    xhr.setRequestHeader('X-EBAY-API-VERSION', configeBayShoppingVersion);
1317
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
1318
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
1319
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
1320
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
1321
    xhr.setRequestHeader('X-EBAY-API-REQUEST-ENCODING', 'XML');
1322
    xhr.setRequestHeader('X-Proxy-URL', configeBayShopping);
1323
 
1324
    return true;
1325
}
1326
 
1327
    </script>
17 - 1328
    <script>includeHTML();</script>
2 - 1329
 
1330
</body>
1331
</html>