Subversion Repositories munaweb

Rev

Rev 53 | Rev 55 | 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>
31
        <div">
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
 
317
    var Title = JsonObj.Title;
318
 
319
    if (Number(ConditionID) === 1000) {
320
        tags.push("Condition: Brand New");
321
    } else {
322
        tags.push("Condition: Preowned");
323
    }
324
 
325
    n = (SKU === undefined ? 0 : SKU.indexOf(" - "));
326
    if (n > 0) {
327
        barcode = SKU.substr(n + 3);
328
        barcode = barcode.substr(barcode.indexOf(" ") + 1);
329
        handle = 'B' + barcode;
330
        barcode = '\'' + barcode;
331
        SKU = SKU.substr(0, n);
332
    } else {
333
        if (categoryName.indexOf("Books") != -1 && ProductListingDetails && ProductListingDetails.ISBN && isNumeric(ProductListingDetails.ISBN)) {
334
            barcode = '\'' + ProductListingDetails.ISBN;
335
            handle = 'B' + ProductListingDetails.ISBN;
336
        } else if (ProductListingDetails && ProductListingDetails.UPC && isNumeric(ProductListingDetails.UPC)) {
337
            barcode = '\'' + ProductListingDetails.UPC;
338
            handle = 'B' + ProductListingDetails.UPC;
339
        } else if (ProductListingDetails && ProductListingDetails.ProductReferenceID && isNumeric(ProductListingDetails.ProductReferenceID)) {
340
            barcode = 'R' + ProductListingDetails.ProductReferenceID;
341
            handle = barcode;
342
        } else {
343
            barcode = 'H' + Title.hashCode();
344
            handle = barcode;
345
        }
346
    }
347
 
348
    userDescription = extractDescription(Description);
16 - 349
    if (ItemSpecifics && ItemSpecifics.NameValueList && PrimaryCategoryName.indexOf('DVD') < 0) {
350
        userDescription += '<table><tbody>';
351
        for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
352
            var itemSpecific = ItemSpecifics.NameValueList[i];
353
            if (itemSpecific.Name != 'All returns accepted' &&
354
                itemSpecific.Name != 'Item must be returned within' &&
355
                itemSpecific.Name != 'Refund will be given as' &&
356
                itemSpecific.Name != 'Return policy details' &&
357
                itemSpecific.Name != 'Restocking Fee' &&
358
                itemSpecific.Name != 'Return shipping will be paid by') {
359
                userDescription += '<tr><td style="padding: 0;">' + itemSpecific.Name + ':</td><td style="padding: 0;">' + itemSpecific.Value + '</td></tr>';
2 - 360
            }
361
        }
16 - 362
        userDescription += '</tbody></table>';
2 - 363
    }
364
 
365
    if (ConditionDescription &&
366
        (userDescription.indexOf('Please view all actual images.') < 0 && userDescription.indexOf('mint condition') < 0)) {
367
        userDescription += '<p>' + ConditionDescription + '</p>';
368
    }
369
 
370
    if (categoryName.indexOf("CDs") != -1) {
371
        categoryName = 'Music CDs';
372
        price = 4.95;
373
    } else if (categoryName.indexOf("Movies") != -1) {
374
        categoryName = 'Movies';
375
        price = 4.95;
376
    } else if (categoryName.indexOf("Books") != -1) {
377
        categoryName = 'Books';
378
        price = 5.95;
379
    } else if (categoryName.indexOf("Trading Cards") != -1) {
380
        if (categoryName.indexOf("Baseball") != -1) {
381
            tags.push('Trading Cards: Baseball');
382
        } else if (categoryName.indexOf("Football") != -1) {
383
            tags.push('Trading Cards: Football');
384
        } else if (categoryName.indexOf("Basketball") != -1) {
385
            tags.push('Trading Cards: Basketball');
386
        } else if (categoryName.indexOf("Soccer") != -1) {
387
            tags.push('Trading Cards: Soccer');
388
        } else if (categoryName.indexOf("Ice Hockey") != -1) {
389
            tags.push('Trading Cards: Ice Hockey');
390
        } else if (categoryName.indexOf("Auto Racing") != -1) {
391
            tags.push('Trading Cards: Auto Racing');
392
        }
393
        categoryName = 'Trading Cards';
394
        price = 1.99;
395
    }
396
    tags.push(categoryName);
397
 
398
    if (liveListing) {
399
        tags.push('_eBay Live');
400
 
53 - 401
        price = round((CurrentPriceValue * 0.90), 1) + 0.05; // always end with 5
2 - 402
        if (categoryName.indexOf("CDs") != -1 && price < 4.95) {
403
            price = 4.95;
404
        } else if (categoryName.indexOf("Movies") != -1 && price < 4.95) {
405
            price = 4.95;
406
        } else if (categoryName.indexOf("Books") != -1 && price < 5.95) {
407
            price = 5.95;
408
        } else if (categoryName.indexOf("Trading Cards") != -1 && price < 1.99) {
409
            price = 1.99;
410
        }
411
    }
412
 
413
    if (JsonObj.ShippingPackageDetails !== undefined) {
414
        if (JsonObj.ShippingPackageDetails.WeightMajor !== undefined) {
415
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMajor.text) * 453.5);
416
        }
417
 
418
        if (JsonObj.ShippingPackageDetails.WeightMinor !== undefined) {
419
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMinor.text) * 28.3);
420
        }
421
    }
422
 
423
    html.push('<tr>');
424
 
425
    html.push(tableCell(handle));
426
    html.push(tableCell(Title));
427
    html.push(tableCell(escapeHtml(userDescription)));
428
    html.push(tableCell("MUNA Trading"));
429
    html.push(tableCell(categoryName));
430
    html.push(tableCell(tags.join(',')));
431
    html.push(tableCell("TRUE"));
28 - 432
    html.push(tableCell("Title"));
433
    html.push(tableCell("Default Title"));
25 - 434
    html.push(tableCell(""));
435
    html.push(tableCell(""));
436
    html.push(tableCell(""));
437
    html.push(tableCell(""));
2 - 438
    html.push(tableCell((SKU !== undefined ? SKU : "")));
25 - 439
    html.push(tableCell(Math.floor(weightInGrams)));
2 - 440
    html.push(tableCell("shopify"));
16 - 441
    html.push(tableCell((Quantity - QuantitySold)));
2 - 442
    html.push(tableCell("deny"));
443
    html.push(tableCell("manual"));
444
    html.push(tableCell(price));
25 - 445
    html.push(tableCell(""));
2 - 446
    html.push(tableCell("TRUE"));
447
    html.push(tableCell("TRUE"));
448
    html.push(tableCell(barcode));
32 - 449
    if (onShopify) {
450
        html.push(tableCell(""));
451
        html.push(tableCell(""));
452
        html.push(tableCell(""));
453
    } else {
454
        html.push(tableCell(PictureURL[0].substr(0, PictureURL[0].lastIndexOf('/') + 1) + '$_57.JPG'));
455
        html.push(tableCell(1));
456
        html.push(tableCell(Title + " Image 1"));
457
    }
25 - 458
    html.push(tableCell("FALSE"));
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(""));
474
    html.push(tableCell(""));
2 - 475
    html.push(tableCell("oz"));
25 - 476
    html.push(tableCell(""));
477
    html.push(tableCell(""));
2 - 478
 
479
    html.push('</tr>');
480
 
32 - 481
    if (!onShopify) {
482
        for (i = 1; i < PictureURL.length; i++) {
483
            html.push('<tr>');
2 - 484
 
32 - 485
            html.push(tableCell(handle));
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(""));
509
            html.push(tableCell(PictureURL[i].substr(0, PictureURL[i].lastIndexOf('/') + 1) + '$_57.JPG'));
510
            html.push(tableCell(i + 1));
511
            html.push(tableCell(Title + " Image " + (i + 1)));
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(""));
531
            html.push(tableCell(""));
2 - 532
 
32 - 533
            html.push('</tr>');
534
        }
2 - 535
    }
536
}
537
 
538
function extractDescription(str) {
539
    var startText = "<!-- *************** Place description here ****************** -->";
540
    var startPos = str.indexOf(startText) + startText.length;
541
    var endPos = str.lastIndexOf("<!-- *************** Place description here ****************** -->");
542
    var userDescription = str.substr(startPos, endPos - startPos);
543
    var parser = new DOMParser();
544
    var htmlDoc = parser.parseFromString(userDescription, "text/html");
545
 
546
    return ((htmlDoc.getElementsByTagName('div')[0] !== undefined ? htmlDoc.getElementsByTagName('div')[0].innerHTML : userDescription));
547
}
548
 
549
function tableEnd() {
550
    html.push('</tbody>');
551
    html.push('</table>');
552
    html.push('</div>');
553
 
554
    document.getElementById("csv").innerHTML = html.join('');
555
}
556
 
557
function addNote(itemId) {
558
    var i;
559
    var xml;
560
 
561
    var xw = new XMLWriter('UTF-8', '1.0');
562
    var xhr = new XMLHttpRequest();
563
 
564
    if (!createAddXMLNote(xw, xhr, 'SetUserNotesRequest', 'SetUserNotes', itemId)) {
565
        return;
566
    }
567
 
568
    xml = xw.flush();
569
    xw.close();
570
 
571
    xhr.onload = function() {
16 - 572
        var jsonObj = XMLparse(xhr.responseXML, false);
573
        var obj = jsonObj.SetUserNotesResponse;
2 - 574
        var returnCode = obj.Ack;
19 - 575
        var str;
2 - 576
 
577
        var x = document.getElementById("results");
578
        if (x.className.indexOf("w3-show") == -1) {
579
            x.className += " w3-show";
580
        }
581
 
582
        if (returnCode == 'Success' || (returnCode == 'Warning' && obj.Errors.ErrorCode == '21917108')) {
19 - 583
            str = '<p>' + itemId + ': <strong>' + returnCode + '</strong></p>';
2 - 584
 
585
            if (returnCode == 'Warning') {
19 - 586
                str += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
2 - 587
            }
19 - 588
 
589
            x.innerHTML += str;
2 - 590
        } else {
591
            x.className += " process-errors";
30 - 592
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';
2 - 593
 
6 - 594
            var errors = getJsonArray(obj.Errors);
19 - 595
            str += "<p>";
6 - 596
            for (i = 0; i < errors.length; i++) {
19 - 597
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 598
            }
19 - 599
            str += "</p>";
600
 
601
            x.innerHTML += str;
2 - 602
        }
603
 
604
        if (obj.Message) {
605
            x.innerHTML += obj.Message;
606
        }
607
 
608
        --notesToAdd;
609
        ++notesAdded;
610
 
611
        updateProgressBar(maxNotesToAdd, notesAdded);
612
    };
613
 
614
    xhr.send(xml);
615
}
616
 
617
function createAddXMLNote(xw, xhr, xmlrequest, callname, itemId) {
618
    var today = new Date();
619
    var todayYYYYMMDD = today.toISOString().slice(0, 10);
620
 
621
    xw.writeStartDocument();
622
    xw.writeStartElement(xmlrequest);
623
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
624
 
625
    xw.writeStartElement('RequesterCredentials');
626
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
627
    xw.writeEndElement(); /* RequesterCredentials */
628
 
629
    xw.writeElementString('ItemID', itemId);
630
    xw.writeElementString('Action', 'AddOrUpdate');
631
    xw.writeElementString('NoteText', 'Exported to Shopify on ' + todayYYYYMMDD);
632
 
633
    xw.writeElementString('ErrorLanguage', 'en_US');
634
    xw.writeElementString('Version', configeBayTradingVersion);
635
    xw.writeElementString('WarningLevel', configWarningLevel);
636
 
637
    xw.writeEndElement(); /* xmlrequest */
638
    xw.writeEndDocument();
639
 
640
    xhr.open('POST', configProxyUrl, true);
641
    xhr.setRequestHeader('Content-Type', 'text/xml');
642
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
643
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
644
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
645
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
646
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
647
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
648
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
649
 
650
    return true;
651
}
652
 
32 - 653
function eBaySearch(itemId, onShopify) {
2 - 654
    var i;
655
    var xml;
656
 
657
    var xw = new XMLWriter('UTF-8', '1.0');
658
    var xhr = new XMLHttpRequest();
659
 
660
    if (!createAddXMLSearch(xw, xhr, 'GetItemRequest', 'GetItem', itemId)) {
661
        return;
662
    }
663
 
664
    xml = xw.flush();
665
    xw.close();
666
 
667
    xhr.onload = function() {
16 - 668
        var jsonObj = XMLparse(xhr.responseXML, false);
669
        var obj = jsonObj.GetItemResponse;
2 - 670
        var returnCode = obj.Ack;
19 - 671
        var str;
2 - 672
 
673
        var x = document.getElementById("results");
674
        if (x.className.indexOf("w3-show") == -1) {
675
            x.className += " w3-show";
676
        }
677
 
678
        if (returnCode == 'Success') {
32 - 679
            tableEntry(obj.Item, onShopify);
2 - 680
        } else {
681
            x.className += " process-errors";
30 - 682
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';
2 - 683
 
6 - 684
            var errors = getJsonArray(obj.Errors);
19 - 685
            str += "<p>";
6 - 686
            for (i = 0; i < errors.length; i++) {
19 - 687
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 688
            }
19 - 689
            str += "</p>";
6 - 690
 
19 - 691
            x.innerHTML += str;
2 - 692
        }
693
 
694
        --pagesToProcess;
695
        ++pagesProcessed;
696
 
697
        updateProgressBar(maxPagesToProcess, pagesProcessed);
698
    };
699
 
700
    xhr.send(xml);
701
}
702
 
703
function createAddXMLSearch(xw, xhr, xmlrequest, callname, itemId) {
704
 
705
    xw.writeStartDocument();
706
    xw.writeStartElement(xmlrequest);
707
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
708
 
709
    xw.writeStartElement('RequesterCredentials');
710
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
711
    xw.writeEndElement(); /* RequesterCredentials */
712
 
713
    xw.writeElementString('ItemID', itemId);
714
    xw.writeElementString('IncludeItemSpecifics', 'true');
715
    xw.writeElementString('DetailLevel', 'ReturnAll');
716
 
717
    xw.writeElementString('ErrorLanguage', 'en_US');
718
    xw.writeElementString('Version', configeBayTradingVersion);
719
    xw.writeElementString('WarningLevel', configWarningLevel);
720
 
721
    xw.writeEndElement(); /* xmlrequest */
722
    xw.writeEndDocument();
723
 
724
    xhr.open('POST', configProxyUrl, true);
725
    xhr.setRequestHeader('Content-Type', 'text/xml');
726
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
727
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
728
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
729
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
730
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
731
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
732
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
733
 
734
    return true;
735
}
736
 
737
function getListings() {
738
    var x;
739
 
740
    if (eBayAuthTokenFlag === false) {
741
        return;
742
    }
743
 
744
    document.getElementById("logging").innerHTML = '';
745
 
746
    x = document.getElementById("results");
747
    if (x.className.indexOf("w3-show") == -1) {
748
        x.className += " w3-show";
749
    }
750
    x.className = x.className.replace("process-errors", "");
751
    x.innerHTML = '<p><strong>Retrieving Listings...</strong></p>';
752
 
32 - 753
    initProgressBar('Getting Items for Export (Step 1/3)');
2 - 754
 
755
    liveListing = (getRadioValue('rptType') == 'liveList');
756
    tableSorterStart();
757
    maxPagesToProcess = 1;
758
    pagesToProcess = 1;
759
    pagesProcessed = 0;
760
    eBaySorterSearch(1);
761
 
762
    function checkpagesToProcess() {
763
        if (pagesToProcess > 0) {
764
            window.setTimeout(checkpagesToProcess, 100); // wait 100 milliseconds
765
        } else {
766
            tableSorterEnd();
767
            endProgressBar();
768
            // fillSorterListings(); is now in tableSorterEnd()
769
        }
770
    }
771
 
772
    checkpagesToProcess();
773
}
774
 
775
function tableSorterStart() {
776
    document.getElementById("logging").innerHTML = '';
777
    html = [];
778
 
779
    html.push('<h3>Items for Export</h3>');
780
    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 - 781
    html.push('<div class="border table-responsive">');
2 - 782
    html.push('<table id="' + tableSorterName + '" class="tablesorter">');
783
    html.push('<thead>');
784
    html.push('<tr>');
785
 
6 - 786
    html.push(tableHeaderCheckbox());
2 - 787
    html.push(tableHeader('Image'));
788
    html.push(tableHeader('Title'));
789
    html.push(tableHeader('Item Id'));
790
    html.push(tableHeader('SKU'));
791
    html.push(tableHeader('Category'));
792
    html.push(tableHeader('Format'));
793
    html.push(tableHeader('Price'));
794
    html.push(tableHeader('Quantity'));
795
    html.push(tableHeader('Views'));
796
    html.push(tableHeader('Watchers'));
797
    html.push(tableHeader(liveListing ? 'Start Date' : 'End Date'));
798
    html.push(tableHeader('Note'));
32 - 799
    html.push(tableHeader('Shopify'));
2 - 800
 
801
    html.push('</tr>');
802
    html.push('</thead>');
803
    html.push('<tbody>');
804
}
805
 
806
function tableSorterEntry(JsonObj) {
807
    var i;
808
    var image;
809
    var title;
810
    var itemId;
811
    var sku;
812
    var format;
813
    var price;
814
    var quantity;
815
    var views;
816
    var watchers;
817
    var listingDate;
818
    var privateNote;
819
    var ebayNote;
820
    var relisted;
16 - 821
    var bidCount;
2 - 822
 
823
    for (i = 0; i < JsonObj.length; i++) {
16 - 824
        image = getJsonValue(JsonObj[i].PictureDetails.GalleryURL).replace('http:', 'https:');
2 - 825
        title = getJsonValue(JsonObj[i].Title);
826
        itemId = getJsonValue(JsonObj[i].ItemID);
827
        sku = getJsonValue(JsonObj[i].SKU);
828
        format = getJsonValue(JsonObj[i].ListingType);
16 - 829
        bidCount = (typeof(JsonObj[i].SellingStatus) === 'object' ? Number(getJsonValue(JsonObj[i].SellingStatus.BidCount)) : 0);
2 - 830
        if (format == 'Chinese') {
831
            format = 'Auction';
832
            price = getJsonValue(JsonObj[i].StartPrice.text);
833
        } else {
834
            format = 'Fixed Price';
835
            price = getJsonValue(JsonObj[i].BuyItNowPrice.text);
836
        }
837
        quantity = getJsonValue(JsonObj[i].QuantityAvailable);
838
        views = '';
16 - 839
        watchers = Number(getJsonValue(JsonObj[i].WatchCount));
840
        listingDate = getJsonValue((liveListing ? JsonObj[i].ListingDetails.StartTime : JsonObj[i].ListingDetails.EndTime)).substr(0, 10);
2 - 841
        privateNote = getJsonValue(JsonObj[i].PrivateNotes);
842
        ebayNote = getJsonValue(JsonObj[i].eBayNotes);
843
        relisted = getJsonValue(JsonObj[i].Relisted);
844
 
845
        if (!liveListing) {
846
            if (privateNote.startsWith("Exported to ") || relisted == 'true' || privateNote.startsWith("Sold via ") || privateNote.startsWith("Relisted As New Item")) {
847
                continue;
848
            }
16 - 849
        } else {
850
            if (bidCount > 0) {
851
                continue;
852
            }
2 - 853
        }
854
 
855
        html.push('<tr>');
856
 
857
        html.push(tableCellCheckbox());
30 - 858
        html.push(tableCell('<img class="img-fluid" src="' + image + '" alt="Gallery Image" style="max-height:100px;max-width:100px;">'));
2 - 859
        html.push(tableCell(title));
860
        html.push(tableCell(itemId));
861
        html.push(tableCell(sku));
862
        html.push(tableCellLabel('Category' + itemId));
863
        html.push(tableCell(format));
864
        html.push(tableCell('$' + price));
865
        html.push(tableCell(quantity));
866
        html.push(tableCellLabel('Views' + itemId));
867
        html.push(tableCell(watchers));
868
        html.push(tableCell(listingDate));
869
        html.push(tableCell(privateNote + ' ' + ebayNote));
32 - 870
        html.push(tableCellLabel('Shopify' + itemId));
2 - 871
 
872
        html.push('</tr>');
873
    }
874
}
875
 
876
function tableSorterEnd() {
877
    html.push('</tbody>');
878
    html.push('</table>');
879
    html.push('</div>');
880
 
881
    document.getElementById("logging").innerHTML = html.join('');
882
 
883
    $(function() {
884
        $("#" + tableSorterName).on('tablesorter-initialized', function() {
885
 
886
            // class name to add on tr when checkbox is checked
887
            var highlightClass = 'checked',
888
                // resort the table after the checkbox is modified?
889
                resort = true,
890
                $table = $(this),
891
                c = this.config,
892
                wo = c && c.widgetOptions,
893
                // include sticky header checkbox; if installed
894
                $sticky = c && wo.$sticky || '',
895
                doChecky = function(c, col) {
896
                    $table
897
                        .children('tbody')
898
                        .children('tr:visible')
899
                        .children('td:nth-child( ' + (parseInt(col, 10) + 1) + ' )')
900
                        .find('input[type=checkbox]')
901
                        .each(function() {
902
                            this.checked = c;
903
                            $(this).trigger('change');
904
                        });
905
                };
906
 
907
            $table
908
                .children('tbody')
909
                .on('change', 'input[type=checkbox]', function() {
910
                    // ignore change if updating all rows
911
                    if ($table[0].ignoreChange) {
912
                        return;
913
                    }
914
                    var $this = $(this);
915
                    $this.closest('tr').toggleClass(highlightClass, this.checked);
19 - 916
                    // resort will jump bqack to the top
917
                    // $this.trigger('updateCell', [$this.closest('td'), resort]);
2 - 918
 
919
                    // handle header
7 - 920
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
2 - 921
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
922
                    var ua = window.navigator.userAgent;
923
                    if (checkedCount === 0) {
924
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', false);
925
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
926
                    } else if (checkedCount === rowCount) {
927
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', true);
928
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
929
                    } else {
930
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
931
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', true);
932
                    }
933
                    $('#selected-rows').html(checkedCount);
934
                })
935
                .end()
936
                .add($sticky)
937
                .find('thead input[type=checkbox]')
938
                // Click on checkbox in table header to toggle all inputs
939
                .on('change', function() {
940
                    // prevent updateCell for every cell
941
                    $table[0].ignoreChange = true;
942
                    var c = this.checked,
943
                        col = $(this).closest('th').attr('data-column');
944
                    doChecky(c, col);
945
                    // update main & sticky header
946
 
947
                    $table.children('tbody').children('tr:visible').toggleClass(highlightClass, c);
948
                    // update all at once
949
                    $table[0].ignoreChange = false;
950
                    $table.trigger('update', [resort]);
951
 
952
                    // handle header
7 - 953
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
2 - 954
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
955
                    var ua = window.navigator.userAgent;
956
                    if (checkedCount === 0) {
957
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', false);
958
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
959
                    } else if (checkedCount === rowCount) {
960
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', true);
961
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
962
                    } else {
963
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
964
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', true);
965
                    }
966
                    $('#selected-rows').html(checkedCount);
967
                })
968
                .on('mouseup', function() {
969
                    return false;
970
                });
971
 
972
        });
973
 
974
        $("#" + tableSorterName).tablesorter({
975
            theme: "blue",
976
            widgets: ["zebra", "stickyHeaders", "filter"],
977
            headers: {
978
                0: {
979
                    sorter: "checkbox"
980
                },
981
                1: {
982
                    sorter: false,
983
                    filter: false
984
                }
985
            },
986
            initialized: function() {
987
                fillSorterListings();
988
            }
989
        });
990
 
991
        $("#" + tableSorterName).bind('filterInit filterEnd', function(event, data) {
992
            $('#filtered-rows').html(data.filteredRows);
993
            $('#total-rows').html(data.totalRows);
994
        });
995
    });
996
}
997
 
998
function eBaySorterSearch(pageNo) {
999
    var i;
1000
    var xml;
1001
 
1002
    var xw = new XMLWriter('UTF-8', '1.0');
1003
    var xhr = new XMLHttpRequest();
1004
 
1005
    if (!createSorterAddXMLSearch(xw, xhr, 'GetMyeBaySelling', pageNo)) {
1006
        return;
1007
    }
1008
 
1009
    xml = xw.flush();
1010
    xw.close();
1011
 
1012
    xhr.onload = function() {
16 - 1013
        var jsonObj = XMLparse(xhr.responseXML, false);
1014
        var obj = jsonObj.GetMyeBaySellingResponse;
2 - 1015
        var returnCode = obj.Ack;
19 - 1016
        var str;
2 - 1017
 
1018
        var objArray = (liveListing ? obj.ActiveList : obj.UnsoldList);
1019
 
1020
        var x = document.getElementById("results");
1021
 
1022
        if (returnCode == 'Success') {
16 - 1023
            tableSorterEntry(objArray.ItemArray.Item);
2 - 1024
 
1025
            if (Number(objArray.PaginationResult.TotalNumberOfPages) > pageNo) {
1026
                maxPagesToProcess = Number(objArray.PaginationResult.TotalNumberOfPages);
1027
                ++pagesToProcess;
1028
                eBaySorterSearch(pageNo + 1);
1029
            }
1030
 
1031
            updateProgressBar(maxPagesToProcess, pagesProcessed);
1032
        } else {
1033
            x.className += " process-errors";
30 - 1034
            str = '<p class="text-danger">' + obj.CorrelationID + ': <strong>' + returnCode + ':</strong></p>';
6 - 1035
            var errors = getJsonArray(obj.Errors);
19 - 1036
            str += "<p>";
6 - 1037
            for (i = 0; i < errors.length; i++) {
19 - 1038
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 1039
            }
19 - 1040
            str += "</p>";
6 - 1041
 
19 - 1042
            x.innerHTML += str;
2 - 1043
        }
1044
 
1045
        --pagesToProcess;
1046
        ++pagesProcessed;
1047
 
1048
        updateProgressBar(maxPagesToProcess, pagesProcessed);
1049
    };
1050
 
1051
    xhr.send(xml);
1052
}
1053
 
1054
function createSorterAddXMLSearch(xw, xhr, callname, pageNo) {
14 - 1055
    var outputSelector;
1056
 
2 - 1057
    xw.writeStartDocument();
1058
    xw.writeStartElement(callname + "Request");
1059
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
1060
 
1061
    xw.writeStartElement('RequesterCredentials');
1062
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
1063
    xw.writeEndElement(); /* RequesterCredentials */
1064
 
1065
    xw.writeElementString('DetailLevel', 'ReturnAll');
1066
    xw.writeStartElement('DeletedFromSoldList');
1067
    xw.writeElementString('Include', 'false');
1068
    xw.writeEndElement(); /* DeletedFromSoldList */
1069
    xw.writeStartElement('DeletedFromUnsoldList');
1070
    xw.writeElementString('Include', 'false');
1071
    xw.writeEndElement(); /* DeletedFromUnsoldList */
1072
    xw.writeStartElement('ScheduledList');
1073
    xw.writeElementString('Include', 'false');
1074
    xw.writeEndElement(); /* ScheduledList */
1075
    xw.writeStartElement('SellingSummary');
1076
    xw.writeElementString('Include', 'false');
1077
    xw.writeEndElement(); /* SellingSummary */
1078
    xw.writeStartElement('SoldList');
1079
    xw.writeElementString('Include', 'false');
1080
    xw.writeEndElement(); /* SoldList */
1081
 
1082
    xw.writeStartElement(liveListing ? 'UnsoldList' : 'ActiveList');
1083
    xw.writeElementString('Include', 'false');
1084
    xw.writeEndElement(); /* ActiveList */
1085
 
1086
    xw.writeStartElement(liveListing ? 'ActiveList' : 'UnsoldList');
1087
    xw.writeElementString('Include', 'true');
1088
    xw.writeElementString('IncludeNotes', 'true');
1089
    xw.writeStartElement('Pagination');
1090
    xw.writeElementString('EntriesPerPage', '200');
1091
    xw.writeElementString('PageNumber', '' + pageNo);
1092
    xw.writeEndElement(); /* Pagination*/
1093
    xw.writeEndElement(); /* UnsoldList> */
1094
 
14 - 1095
    outputSelector = liveListing ? 'ActiveList.' : 'UnsoldList.';
1096
 
16 - 1097
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SellingStatus.BidCount');
14 - 1098
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.BuyItNowPrice');
1099
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.eBayNotes');
1100
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ItemID');
16 - 1101
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingDetails.' + (liveListing ? 'StartTime' : 'EndTime'));
14 - 1102
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingType');
1103
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PrivateNotes');
1104
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.QuantityAvailable');
1105
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PictureDetails');
1106
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Relisted');
1107
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SKU');
1108
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Title');
1109
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.StartPrice');
1110
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.WatchCount');
1111
    xw.writeElementString('OutputSelector', outputSelector + 'PaginationResult');
1112
 
2 - 1113
    xw.writeElementString('ErrorLanguage', 'en_US');
1114
    xw.writeElementString('Version', configeBayTradingVersion);
1115
    xw.writeElementString('WarningLevel', configWarningLevel);
1116
 
1117
    xw.writeEndElement(); /* xmlrequest */
1118
    xw.writeEndDocument();
1119
 
1120
    xhr.open('POST', configProxyUrl, true);
1121
    xhr.setRequestHeader('Content-Type', 'text/xml');
1122
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
1123
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
1124
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
1125
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
1126
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
1127
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
1128
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
1129
 
1130
    return true;
1131
}
1132
 
1133
function fillSorterListings() {
1134
    var i;
1135
    var x = document.getElementById(tableSorterName);
1136
    var fillList = [];
1137
    var maxItems = 20;
1138
 
1139
    listingsToFill = 0;
1140
    maxListingsToFill = 0;
1141
    listingsFilled = 0;
1142
 
32 - 1143
    initProgressBar('Filling Listing Information (Step 2/3)');
2 - 1144
 
1145
    for (i = 2; i < x.rows.length; i++) {
1146
        fillList.push(x.rows[i].cells[3].innerHTML);
1147
    }
6 - 1148
 
16 - 1149
    for (i = 0; (i * maxItems) < fillList.length; i++) {
2 - 1150
        ++listingsToFill;
1151
        ++maxListingsToFill;
1152
        fillSorterListing(fillList.slice(i * maxItems, (i + 1) * maxItems));
1153
    }
1154
 
1155
    function checkListingsToFill() {
1156
        if (listingsToFill > 0) {
1157
            window.setTimeout(checkListingsToFill, 100); // wait 100 milliseconds
1158
        } else {
1159
            $("#" + tableSorterName).trigger("update");
1160
 
1161
            endProgressBar();
32 - 1162
            findOnShopify();
1163
        }
1164
    }
2 - 1165
 
32 - 1166
    checkListingsToFill();
1167
}
1168
 
1169
function findOnShopify() {
1170
    var i;
1171
    var x = document.getElementById(tableSorterName);
1172
 
1173
    listingsToFind = 0;
1174
    maxListingsToFind = 0;
1175
    listingsFound = 0;
1176
 
1177
    initProgressBar('Finding Listings already on Shopify (Step 3/3)');
1178
 
1179
    for (i = 2; i < x.rows.length; i++) {
1180
        ++listingsToFind;
1181
        ++maxListingsToFind;
54 - 1182
        findShopifyListing(x.rows[i].cells[3].innerHTML, x.rows[i].cells[2].innerText).then(function(env) {
32 - 1183
		    --listingsToFind;
1184
            ++listingsFound;
1185
            updateProgressBar(maxListingsToFind, listingsFound);
1186
        });
1187
    }
1188
 
1189
    function checkListingsToFind() {
1190
        if (listingsToFind > 0) {
1191
            window.setTimeout(checkListingsToFind, 100); // wait 100 milliseconds
1192
        } else {
1193
            $("#" + tableSorterName).trigger("update");
1194
 
1195
            endProgressBar();
1196
 
2 - 1197
            x = document.getElementById("form1div");
1198
            x.className = x.className.replace(" w3-show", "");
1199
            x = document.getElementById("form2div");
1200
            x.className += " w3-show";
1201
 
1202
            x = document.getElementById("results");
1203
            x.innerHTML += '<p><strong>Report Finished!</strong></p>';
1204
            if (!x.className.includes("process-errors")) {
1205
                setTimeout(function() {
1206
                    x.className = x.className.replace(" w3-show", "");
1207
                }, 3000);
1208
            }
1209
        }
1210
    }
1211
 
32 - 1212
    checkListingsToFind();
2 - 1213
}
1214
 
32 - 1215
const findShopifyListing = stopcock(function request(itemId, title) {
1216
	var xhttp = new XMLHttpRequest();
1217
	xhttp.onreadystatechange = function() {
1218
		if (this.readyState == 4 && this.status == 200) {
1219
			var json = JSON.parse(this.responseText);
1220
			if (json.count !== undefined) {
1221
			    var x = document.getElementById('Shopify' + itemId);
1222
			    x.innerHTML = (json.count == 0 ? 'No' : 'Yes');
1223
			}
1224
 
1225
            return Promise.resolve(true);
1226
		}
1227
	};
1228
 
54 - 1229
// xxxxx if (!title.includes("&")) { return; } // xxxxx
1230
 
53 - 1231
    title = cleanTitleForShopifySearch(title);
1232
 
32 - 1233
	xhttp.open("GET", configProxyUrl, true);
40 - 1234
	xhttp.setRequestHeader("X-Proxy-Url", configShopifyUrl + configShopifyProductCountUrl + '?title=' + title);
32 - 1235
	xhttp.setRequestHeader("X-LEAVE-ENCODED", "1");
1236
	xhttp.send();
1237
});
1238
 
2 - 1239
function fillSorterListing(itemIdList) {
1240
    var i;
1241
    var xml;
1242
 
1243
    var xw = new XMLWriter('UTF-8', '1.0');
1244
    var xhr = new XMLHttpRequest();
1245
 
1246
    if (!createSorterFillXMLSearch(xw, xhr, 'GetMultipleItems', itemIdList)) {
1247
        return;
1248
    }
1249
 
1250
    xml = xw.flush();
1251
    xw.close();
1252
 
1253
    xhr.onload = function() {
16 - 1254
        var jsonObj = XMLparse(xhr.responseXML, false);
1255
        var obj = jsonObj.GetMultipleItemsResponse;
2 - 1256
        var returnCode = obj.Ack;
19 - 1257
        var str;
2 - 1258
 
1259
        var x = document.getElementById("results");
1260
 
1261
        if (returnCode == 'Success') {
1262
            for (i = 0; i < obj.Item.length; i++) {
1263
                var itemId = getJsonValue(obj.Item[i].ItemID);
1264
                document.getElementById("Views" + itemId).innerHTML = getJsonValue(obj.Item[i].HitCount);
1265
                document.getElementById("Category" + itemId).innerHTML = getJsonValue(obj.Item[i].PrimaryCategoryName);
6 - 1266
            }
2 - 1267
        } else {
1268
            x.className += " process-errors";
30 - 1269
            str = '<p class="text-danger"><strong>' + returnCode + ':</strong></p>';
2 - 1270
 
6 - 1271
            var errors = getJsonArray(obj.Errors);
19 - 1272
            str += "<p>";
6 - 1273
            for (i = 0; i < errors.length; i++) {
19 - 1274
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
2 - 1275
            }
1276
            x.innerHTML += "</p>";
19 - 1277
 
1278
            x.innerHTML += str;
2 - 1279
        }
1280
 
1281
        --listingsToFill;
1282
        ++listingsFilled;
1283
        updateProgressBar(maxListingsToFill, listingsFilled);
1284
    };
1285
 
1286
    xhr.send(xml);
1287
}
1288
 
1289
function createSorterFillXMLSearch(xw, xhr, callname, itemIdList) {
1290
    var i;
6 - 1291
 
2 - 1292
    xw.writeStartDocument();
1293
    xw.writeStartElement(callname + "Request");
1294
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
1295
 
1296
    for (i = 0; i < itemIdList.length; i++) {
1297
        xw.writeElementString('ItemID', itemIdList[i]);
1298
    }
1299
 
1300
    xw.writeElementString('ErrorLanguage', 'en_US');
1301
    xw.writeElementString('Version', configeBayShoppingVersion);
1302
    xw.writeElementString('WarningLevel', configWarningLevel);
1303
 
1304
    xw.writeEndElement(); /* xmlrequest */
1305
    xw.writeEndDocument();
1306
 
1307
    xhr.open('POST', configProxyUrl, true);
1308
    xhr.setRequestHeader('Content-Type', 'text/xml');
1309
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
1310
    xhr.setRequestHeader('X-EBAY-API-VERSION', configeBayShoppingVersion);
1311
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
1312
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
1313
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
1314
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
1315
    xhr.setRequestHeader('X-EBAY-API-REQUEST-ENCODING', 'XML');
1316
    xhr.setRequestHeader('X-Proxy-URL', configeBayShopping);
1317
 
1318
    return true;
1319
}
1320
 
1321
    </script>
17 - 1322
    <script>includeHTML();</script>
2 - 1323
 
1324
</body>
1325
</html>