forked from polidario/Elana
/
footer.php
105 lines (91 loc) · 2.77 KB
/
footer.php
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
</main>
<script src="https://unpkg.com/@shopify/app-bridge@2"></script>
<script src="https://unpkg.com/@shopify/app-bridge-utils"></script>
<script src="https://unpkg.com/axios/dist/axios.js"></script>
<script>
var AppBridge = window['app-bridge'];
var AppBridgeUtil = window['app-bridge-utils'];
var actions = window['app-bridge'].actions;
var createApp = AppBridge.default;
var TitleBar = actions.TitleBar;
var Button = actions.Button;
var Redirect = actions.Redirect;
var Modal = actions.Modal;
var app = createApp({
apiKey: 'ebbf39c49d3838a570888b4c4cd52461',
shopOrigin: '<?php echo $shopify->get_url(); ?>'
});
const modalOpt = {
title: 'Example Title',
message: 'I am the content inside of the modal'
};
const exampleModal = Modal.create(app, modalOpt);
const redirect = Redirect.create(app);
var installScriptBtn = Button.create(app, { label: 'Install Script Tag' });
installScriptBtn.subscribe(Button.Action.CLICK, data => {
exampleModal.dispatch(Modal.Action.OPEN);
});
const titleBarOpt = {
title: 'App',
buttons: {
primary: installScriptBtn
}
}
const appTitleBar = TitleBar.create(app, titleBarOpt);
//============================================
// GETTING SESSION TOKEN
//============================================
const getSessionToken = AppBridgeUtil.getSessionToken;
getSessionToken(app).then(token => {
var formData = new FormData();
formData.append('token', token);
fetch('verify_session.php', {
method: 'POST',
header: {
'Content-Type': 'application/json'
},
body: formData
})
.then(response => response.json())
.then(data => {
console.log(data);
if(data.success) {
axios({
method: 'POST',
url: 'authenticatedFetch.php',
data: {
shop: data.shop.host,
query: `query {
products(first: 2) {
edges {
node {
id
title
description
images(first: 1) {
edges {
node {
originalSrc
}
}
}
status
}
}
}
}
`
},
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer: ' + token
}
}).then((response) => {
//console.log(response.data);
})
}
});
});
</script>
</body>
</html>