-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopStevieDetailsGrabber.js
75 lines (69 loc) · 2.13 KB
/
shopStevieDetailsGrabber.js
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
function downloadCsv() {
getCsv(function(d) {
var dataStr = "data:text/csv;charset=utf-8," + d;
var encodedUri = encodeURI(dataStr);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "import.csv");
document.body.appendChild(link);
link.click();
link.remove();
})
}
function getDetails() {
objs = shop.productSingleObject
count = Math.max(objs.variants.length, objs.images.length);
for (var i = 0; i < count; i++) {
if (typeof string === 'undefined') {
var string = [objs.title,'"'+objs.description+'"',objs.vendor,objs.type,'false','Size'].join(',')
} else {
string += ',,,,,'
}
string += ','+objs.handle
if (typeof objs.variants[i] !== 'undefined') {
variant = objs.variants[i]
price = Math.max(variant.compare_at_price,variant.price)/100
string += ','+variant.public_title
string += ','+variant.sku
string += ','+variant.weight
string += ',shopify'
string += ',0'
string += ',deny'
string += ',manual'
string += ','+price
string += ',true'
string += ',false'
string += ',oz'
} else {
string += ',,,,,,,,,,,'
}
if (typeof objs.images[i] !== 'undefined') {
img =
string += ','+'https:'+objs.images[i]
string += ','+(i+1)
} else {
string += ',,'
}
string += "\n"
}
appendCsv(string, function() {
if (window.confirm('Download?')) {
window.downloadCsv()
};
})
}
function getCsv(callback) {
params = {'a':'get'}
cll(params, callback)
}
function appendCsv(data, callback) {
params = {'a':'append','d':data}
cll(params, callback)
}
function cll(params, callback) {
params['scrt'] = 'asdfpwoiernakjnvaskfn'
jQuery.post('https://my-serve.com/shopStevieDetailsGrabber.php', params, callback).fail(function() {
alert("error with "+params['a']);
})
}
// javascript:(function(){if(typeof ssg_script=='undefined'){ssg_script=document.createElement('SCRIPT');ssg_script.type='text/javascript';ssg_script.src='https://my-serve.com/shopStevieDetailsGrabber.js';ssg_script.onload=function(){getDetails();};document.getElementsByTagName('head')[0].appendChild(ssg_script);}else{getDetails();}})();