inventory.php
19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<?php
require_once(__DIR__ . "/support.php");
/*
* We need to display some obvious errors.
*
* Variants need managed stock in every variant.
*
* Simple needs to be managed stock.
*
*/
require_once(__DIR__.'/../model/AffinityTitleRule.php');
require_once(__DIR__.'/../model/AffinityShippingRule.php');
?>
<?php
if (!empty($_GET['id'])) {
require_once(__DIR__.'/../ecommerce-adapters/AffinityEcommerceProduct.php');
$data = AffinityEbayInventory::inventorysingle($_GET['id']);
if (empty($data)) {
?>
<div class="ebayaffinity-header ebayaffinity-ebayaffinity-header"></div>
<p>This item could not be found.</p>
<?php
return;
}
$titleRuleResult = AffinityTitleRule::generate($data['product']);
$shipRuleResult = AffinityShippingRule::generate($data['product']);
?>
<script type="text/javascript">
ebayaffinity_ajax_invmode = 1;
</script>
<div class="ebayaffinity-header ebayaffinity-ebayaffinity-header">
<?php
if (!empty($data['ebayitemid'])) {
?>
<a href="<?php print get_option('ebayaffinity_ebaysite')?>itm/<?php print esc_html($data['ebayitemid']) ?>" target="_blank" class="ebayaffinity-header-eye"><div>View eBay Listing</div></a>
<?php
}
?>
<a href="post.php?post=<?php print intval($_GET['id'])?>&action=edit" class="ebayaffinity-header-eye ebayaffinity-header-cart <?php print (empty($data['ebayitemid']))?'':'ebayaffinity-header-cart-left'?>"><div>Edit Product</div></a>
<a href="admin.php?page=ebay-sync-inventory&id=<?php print intval($_GET['id'])?>&sync=1" class="ebayaffinity-header-eye ebayaffinity-header-sync <?php print (empty($data['ebayitemid']))?'ebayaffinity-header-cart-left':'ebayaffinity-header-cart-left-left'?>"><div>Sync to eBay</div></a>
</div>
<?php
$warnings = array();
if (empty($data['server_warning'])) {
$b = array();
} else {
$b = json_decode($data['server_warning'], true);
}
if (!empty($b)) {
foreach ($b as $el) {
$warnings[]= '<p>Warning: '.esc_html($el).'</p>';
}
}
if (empty($data['client_warning'])) {
$b = array();
} else {
$b = json_decode($data['client_warning'], true);
}
if (!empty($b)) {
foreach ($b as $el) {
$warnings[]= '<p>Warning: '.esc_html($el).'</p>';
}
}
if (empty($data['server_error'])) {
$a = array();
} else {
$a = json_decode($data['server_error'], true);
}
$errors = array();
if (!empty($a)) {
foreach ($a as $el) {
$errors []= '<p>'.esc_html($el).'</p>';
}
}
if (empty($data['client_error'])) {
$a = array();
} else {
$a = json_decode($data['client_error'], true);
}
if (!empty($a)) {
foreach ($a as $el) {
$errors []= '<p>'.esc_html($el).'</p>';
}
}
$errors = array_unique($errors);
$warnings = array_unique($warnings);
$warnings_n = array();
foreach ($warnings as $warning) {
if (stripos($warning, "re not opted-in to Business Policies") === false) {
$warnings_n[] = $warning;
}
}
$warnings = $warnings_n;
$errors_n = array();
foreach ($errors as $error) {
if (stripos($error, "The specified UUID has already been used") !== false) {
$errors_n[] = '<p>Re-listing this item has been temporarily delayed. This item should be automatically re-listed soon.</p>';
} else if (stripos($error, "Condition is required for this category") !== false) {
$errors_n[] = '<p>The item condition you selected is not available in this eBay category.</p>';
} else if (stripos($error, "Server returned an unexpected error (http response code: 404).") !== false) {
$errors_n[] = '<p>Product sync has been delayed. This issue should be resolved automatically.</p>';
} else {
$errors_n[] = $error;
}
}
$errors = $errors_n;
if (count($errors) > 0 || count($warnings) > 0) {
?>
<div class="ebayaffinity-big-error">
<div>This product has errors</div>
<?php
print implode('', array_unique($warnings));
print implode('', array_unique($errors));
?>
</div>
<?php
}
?>
<div class="ebayaffinity-inv-detail" data-id="<?php print intval($_GET['id'])?>">
<div class="ebayaffinity-inv-detail-main">
<div class="ebayaffinity-setting">
<div class="ebayaffinity-inv-detail-main-left">
<?php print $data['img'][0]?>
</div>
<div class="ebayaffinity-inv-detail-main-right">
<?php
if (count($data['imgs']) > 1) {
?>
<div class="ebayaffinity-scrollerer-container ebayaffinity-scrollerer-container-mob">
<?php
if (count($data['imgs']) > 2) {
?><div class="ebayaffinity-scrollerer-left"><span>∟</span></div><?php
}
?>
<div class="ebayaffinity-scrollerer">
<?php
foreach ($data['imgs'] as $k=>$img) {
$h = explode('height="', $img[1]);
$h = explode('"', $h[1]);
$h = $h[0];
$h = (98 - $h) / 2;
$img[1] = str_replace(' height="', ' data-big="'.esc_html($img[0]).'" style="margin-top: '.$h.'px" height="', $img[1]);
?><div class="ebayaffinity-scrollbox <?php print empty($k)?'ebayaffinity-scrollbox-selected':''?>"><?php print $img[1]?></div><?php
}
?>
</div>
<?php
if (count($data['imgs']) > 2) {
?><div class="ebayaffinity-scrollerer-right"><span>∟</span></div><?php
}
?>
</div>
<?php
}
?>
<div class="ebayaffinity-inv-detail-title">
<?php print esc_html($data['title'])?>
</div>
<div class="ebayaffinity-inv-detail-data-section">
<table>
<tr>
<td>Regular Price</td>
<td><strong><?php print $data['rrp_price']?></strong></td>
</tr>
<tr>
<td>Sale Price</td>
<td><strong><?php print $data['sale_price']?></strong></td>
</tr>
<tr>
<td>eBay Price</td>
<td><strong><?php print $data['price']?></strong></td>
</tr>
<?php
if (!empty($data['sku'])) {
?>
<tr>
<td>SKU</td>
<td><?php print $data['sku']?></td>
</tr>
<?php
}
?>
<tr>
<td>eBay Item ID</td>
<td>
<?php
if (!empty($data['ebayitemid'])) {
?>
<a target="_blank" href="<?php print get_option('ebayaffinity_ebaysite')?>itm/<?php print esc_html($data['ebayitemid']) ?>"><?php print esc_html($data['ebayitemid']) ?></a>
<?php
}
?>
</td>
</tr>
<tr data-id="<?php print esc_html($_GET['id'])?>">
<td>Visible on eBay Store</td>
<td><div class="ebayaffinity-switch-on-off ebayaffinity-switch-<?php print $data['blocked']==1?'off':'on'?>"><div> </div></div></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<?php
if (count($data['imgs']) > 1) {
?>
<div class="ebayaffinity-scrollerer-container">
<?php
if (count($data['imgs']) > 4) {
?><div class="ebayaffinity-scrollerer-left"><span>∟</span></div><?php
}
?>
<div class="ebayaffinity-scrollerer">
<?php
foreach ($data['imgs'] as $k=>$img) {
$h = explode('height="', $img[1]);
$h = explode('"', $h[1]);
$h = $h[0];
$h = (98 - $h) / 2;
$img[1] = str_replace(' height="', ' data-big="'.esc_html($img[0]).'" style="margin-top: '.$h.'px" height="', $img[1]);
?><div class="ebayaffinity-scrollbox <?php print empty($k)?'ebayaffinity-scrollbox-selected':''?>"><?php print $img[1]?></div><?php
}
?>
</div>
<?php
if (count($data['imgs']) > 4) {
?><div class="ebayaffinity-scrollerer-right"><span>∟</span></div><?php
}
?>
</div>
<?php
}
?>
<div class="ebayaffinity-abs">
<a href="admin.php?page=ebay-sync-title-optimisation" class="ebayaffinity-abs-edit"><span>Edit title rules</span></a>
</div>
<div class="ebayaffinity-inv-detail-data-section-clicker ebayaffinity-inv-detail-data-section-clicker-off ebayaffinity-inv-detail-data-section-clicker-disabled">Item title</div>
<div class="ebayaffinity-inv-detail-data-section ebayaffinity-inv-detail-data-section-rule-box" style="display: block;">
<form autocomplete="off" method="post" action="admin.php?page=ebay-sync-inventory&id=<?php print intval($_GET['id'])?>">
<table class="ebayaffinity-inv-detail-data-section-rule">
<tr>
<th>Title customisation rule</th>
<th>Original title</th>
<th>New title</th>
<th></th>
</tr>
<tr>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Title customisation rule</span>
<select name="titlerule" class="ebayaffinity-inv-detail-sel">
<option value="0">Inherit</option>
<?php
$rules = AffinityTitleRule::getAllRules();
foreach ($rules as $rule) {
?>
<option <?php print ($rule->id==$titleRuleResult[0])?'selected':''?> value="<?php print intval($rule->id)?>">Title rule #<?php print intval($rule->id)?></option>
<?php
}
?>
</select>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Original title</span>
<?php print esc_html($data['title'])?>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">New title</span>
<?php print esc_html($titleRuleResult[1])?>
</td>
<td style="text-align: right !important;"><input type="submit" class="ebayaffinity-settingssave" value="Save"></td>
</table>
</form>
</div>
<?php
require_once(__DIR__.'/../model/AffinityEbayCategory.php');
$cats = AffinityEbayInventory::categoryset(true, true);
$eids = array();
if (!empty($data['ebaycategory'])) {
$eids[] = $data['ebaycategory'];
}
foreach ($data['categories'] as $v) {
if (!empty($v['ebaycategory'])) {
$eids[] = $v['ebaycategory'];
break;
}
}
if (!empty($eids)) {
$ecats = AffinityEbayCategory::getAlleBay($eids);
}
$ecattxt = '';
foreach ($eids as $eid) {
foreach ($ecats as $ecat) {
if ($eid == $ecat->categoryId) {
if (empty($ecattxt)) {
$ecattxt = $ecat->catname;
}
}
}
}
?>
<div class="ebayaffinity-inv-detail-data-section-clicker ebayaffinity-inv-detail-data-section-clicker-off ebayaffinity-inv-detail-data-section-clicker-disabled">Categories</div>
<div class="ebayaffinity-inv-detail-data-section ebayaffinity-inv-detail-data-section-rule-box" style="display: block;">
<form action="admin.php?page=ebay-sync-inventory&id=14" method="post" autocomplete="off">
<table class="ebayaffinity-inv-detail-data-section-rule">
<tr>
<th>Original category</th>
<th>eBay category</th>
<tr>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Original category</span>
<?php
foreach ($data['categories'] as $k=>$v) {
?>
<p><?php print AffinityEbayCategory::showWooCatName($cats, $k, true)?><span class="ebayaffinity-rightblue" style="visibility: hidden;">›</span></p>
<?php
}
?>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">eBay category</span>
<p>
<?php print str_replace('>', '<span class="ebayaffinity-rightblue">›</span>', esc_html($ecattxt))?><span class="ebayaffinity-rightblue" style="visibility: hidden;">›</span>
</p>
</td>
<td><div class="ebayaffinity-inv-detail-sel ebayaffinity-prod-map-cat">Map to eBay category</div></td>
</tr>
</table>
</form>
</div>
<?php
if (count($data['variations']) > 0) {
?>
<div class="ebayaffinity-inv-detail-data-section-clicker ebayaffinity-inv-detail-data-section-clicker-off ebayaffinity-inv-detail-data-section-clicker-disabled">Variations</div>
<div class="ebayaffinity-inv-detail-data-section ebayaffinity-inv-detail-data-section-rule-box ebayaffinity-inv-detail-data-section-rule-box-nopad" style="display: block;">
<form autocomplete="off" method="post" action="admin.php?page=ebay-sync-inventory&id=<?php print intval($_GET['id'])?>">
<table class="ebayaffinity-inv-detail-data-section-rule ebayaffinity-inv-detail-data-section-rule-lined">
<tr>
<th> </th>
<th>SKU</th>
<th>Regular price</th>
<th>Sale price</th>
<th>eBay price</th>
<?php
$karr = array();
foreach ($data['variations'] as $v) {
foreach ($v['attributes'] as $kk=>$vv) {
$karr[] = $kk;
?>
<th><?php print esc_html($kk)?></th>
<?php
}
break;
}
?>
</tr>
<?php
foreach ($data['variations'] as $v) {
?>
<tr>
<td><?php print $v['img']?></td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">SKU</span>
<?php print esc_html($v['sku'])?>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Regular price</span>
<?php print $v['rrp_price']?>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Sale price</span>
<?php print $v['sale_price']?>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">eBay price</span>
<?php print $v['price']?>
</td>
<?php
foreach ($karr as $el) {
?>
<td>
<span class="ebayaffinity-inv-detail-mini-title"><?php print esc_html($el)?></span>
<?php print $v['attributes'][$el]?>
</td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</form>
</div>
<?php
}
$rules = AffinityShippingRule::getAllRules();
?>
<div class="ebayaffinity-abs">
<a href="admin.php?page=ebay-sync-settings&pnum=3" class="ebayaffinity-abs-edit"><span>Edit shipping options</span></a>
</div>
<div class="ebayaffinity-rule-container">
<div class="ebayaffinity-inv-detail-data-section-clicker ebayaffinity-inv-detail-data-section-clicker-off ebayaffinity-inv-detail-data-section-clicker-disabled">Shipping</div>
<div class="ebayaffinity-inv-detail-data-section ebayaffinity-inv-detail-data-section-rule-box" style="display: block;">
<form autocomplete="off" method="post" action="admin.php?page=ebay-sync-inventory&id=<?php print intval($_GET['id'])?>">
<table class="ebayaffinity-inv-detail-data-section-rule">
<tr>
<th>Shipping option</th>
<th>Standard shipping price</th>
<th>Express shipping price</th>
<th></th>
</tr>
<tr>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Shipping option</span>
<select name="shiprule" class="ebayaffinity-inv-detail-sel">
<option value="0">Inherit</option>
<?php
$rules = AffinityShippingRule::getAllRules();
foreach ($rules as $rule) {
?>
<option <?php print ($rule->id==($shipRuleResult['ruleid']))?'selected':''?> value="<?php print intval($rule->id)?>">Shipping rule #<?php print intval($rule->id)?></option>
<?php
}
?>
</select>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Standard shipping price</span>
<?php print esc_html(empty($shipRuleResult['standard_freeshipping'])?('$'.$shipRuleResult['standard_fee']):'FREE')?>
</td>
<td>
<span class="ebayaffinity-inv-detail-mini-title">Express shipping price</span>
<?php print esc_html(empty($shipRuleResult['express_freeshipping'])?('$'.$shipRuleResult['express_fee']):'FREE')?>
</td>
<td style="text-align: right !important;"><input type="submit" class="ebayaffinity-settingssave" value="Save"></td>
</table>
</form>
</div>
</div>
<div class="ebayaffinity-inv-detail-data-section-clicker ebayaffinity-inv-detail-data-section-clicker-off ebayaffinity-inv-detail-data-section-clicker-disabled">Item descriptions</div>
<div class="ebayaffinity-inv-detail-data-section ebayaffinity-inv-detail-data-section-rule-box ebayaffinity-inv-detail-data-section-rule-box-desc" style="display: block;">
<form action="admin.php?page=ebay-sync-inventory&id=14" method="post" autocomplete="off">
<table>
<tr>
<th></th>
</tr>
<tr>
<th>WooCommerce description</th>
<td>
<span class="ebayaffinity-inv-detail-mini-title">WooCommerce description</span>
<div class="ebayaffinity-inv-detail-desc"><?php print $data['desc']?></div>
</td>
</tr>
<tr>
<th>eBay description</th>
<td>
<span class="ebayaffinity-inv-detail-mini-title">eBay description</span>
<?php
if (empty($data['ebaydesc'])) {
?>
This can be created on the edit product page: <a href="post.php?post=<?php print intval($_GET['id'])?>&action=edit">here</a>.
<?php
} else {
?>
<div class="ebayaffinity-inv-detail-desc"><?php print $data['ebaydesc']?></div>
<?php
}
?>
</td>
</tr>
</table>
</form>
</div>
</div>
<?php
} else {
$data = AffinityEbayInventory::inventoryset();
$found = $data[1];
$minprice = $data[2];
$maxprice = $data[3];
$data = $data[0];
$uri = explode('?', $_SERVER['REQUEST_URI']);
$uri = $uri[0];
?>
<div class="ebayaffinity-header">
<a class="ebayaffinity-filter" href="#"></a>
<form action="admin.php" autocomplete="off">
<div class="ebayaffinity-selectinvvisprodall">
<select name="selectinvvisprodall" class="ebayaffinity-select">
<option value="0" selected="selected">Visibility</option>
<option value="1">On</option>
<option value="2">Off</option>
</select>
</div>
<div class="ebayaffinity-search">
<input type="hidden" name="page" value="ebay-sync-inventory">
<input type="text" placeholder="Search for a product" name="s" value="<?php print esc_html(stripslashes($_GET['s']))?>">
</div>
</form>
<span>Inventory</span>
<em><?php print intval($found)?> product<?php print ($found==1)?'':'s'?></em>
</div>
<form action="admin.php" autocomplete="off" id="ebayaffinity-inv-filter-form">
<?php
require_once(__DIR__.'/filter.php');
?>
</form>
<form action="admin.php?page=ebay-sync-inventory" autocomplete="off" method="post">
<div class="ebayaffinity-inv-block">
<table class="ebayaffinity-inv-table ebayaffinity-inv-table-nar">
<tr>
<th><input type="checkbox" id="invvisprodall"></th>
<th colspan="2">Product</th>
<th class="ebayaffinity-not-mobile">Regular Price</th>
<th class="ebayaffinity-not-mobile">Sale Price</th>
<th>eBay Price</th>
<th class="ebayaffinity-not-mobile ebayaffinity-not-tablet">SKU</th>
<th class="ebayaffinity-not-mobile">Visibility</th>
<th class="ebayaffinity-not-mobile">Listing Error</th>
</tr>
<?php
foreach ($data as $datum) {
?>
<tr data-id="<?php print esc_html($datum['id'])?>">
<td><input type="checkbox" class="invvisprod"></td>
<td>
<a href="admin.php?page=ebay-sync-inventory&id=<?php print $datum['id']?>">
<?php print $datum['img']?>
</a>
</td>
<td>
<a href="admin.php?page=ebay-sync-inventory&id=<?php print $datum['id']?>">
<?php print esc_html($datum['title'])?>
</a>
</td>
<td class="ebayaffinity-not-mobile"><?php print $datum['rrp_price']?></td>
<td class="ebayaffinity-not-mobile"><?php print $datum['sale_price']?></td>
<td><?php print $datum['price']?></td>
<td class="ebayaffinity-not-mobile ebayaffinity-not-tablet"><?php print esc_html($datum['sku'])?></td>
<td class="ebayaffinity-not-mobile"><div class="ebayaffinity-switch-on-off ebayaffinity-switch-<?php print $datum['blocked']==1?'off':'on'?>"><div> </div></div></td>
<td class="ebayaffinity-not-mobile">
<?php
if (!empty($datum['lasterror'])) {
?>
<div class="ebayaffinity-lasterror"><div><?php print nl2br(esc_html($datum['lasterror']))?></div></div>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</table>
<?php
global $wp_query, $wp_rewrite;
if ($wp_query->max_num_pages > 1) {
$format = '';
$format .= '?paged=%#%';
?>
<nav class="woocommerce-pagination">
<?php
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
'base' => esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ),
'format' => $format,
'add_args' => false,
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $wp_query->max_num_pages,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3
) ) );
?>
</nav>
<?php
}
wp_reset_postdata();
?>
</div>
</form>
<?php
}
require_once(__DIR__.'/float.php');