-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_tags.php
91 lines (77 loc) · 2.81 KB
/
script_tags.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
<?php
include_once("includes/mysql_connect.php");
include_once("includes/shopify.php");
$shopify = new shopify();
$parameters = $_GET;
include_once("includes/check_token.php");
$script_url = 'https://6ca8-190-104-119-240.ngrok.io/elana/scripts/elana.js';
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if($_POST ['action_type'] == 'create_script'){
$mutation = array ("mutation" => 'mutation {
scriptTagCreate (input:{
src:"' . $script_url . '"
displayScope : ALL
}) {
scriptTag {
id
}
userErrors{
field
message
}
}
}' );
$create_script = $shopify -> graphql($mutation);
// $scriptTag_data = array(
// "script_tag" => array(
// "event" => "onload",
// "src" => $script_url
// )
// );
// $create_script = $shopify ->rest_api('/admin/api/2021-07/script_tags.json', $scriptTag_data, 'POST');
// $create_script = json_decode ($create_script['body'], true);
//echo print_r($create_script);
}
if($_POST ['action_type'] == 'delete_script'){
$script_tag = array('src' => $script_url);
$get_script = $shopify ->rest_api('/admin/api/2021-07/script_tags.json', $script_tag, 'GET');
$get_script = json_decode ($get_script['body'], true);
foreach ($get_script ['script_tags'] as $script) {
$delete_script = $shopify ->rest_api('/admin/api/2021-07/script_tags/' . $script['id'] . '.json', array(), 'DELETE');
}
}
}
$scriptTags = $shopify ->rest_api('/admin/api/2021-04/script_tags.json', array(), 'GET');
$scriptTags = json_decode ($scriptTags['body'], true);
// echo print_r($scriptTags);
?>
<?php include_once("headers.php")?>
<section >
<aside>
<h2> Install script tag </h2>
<p>click install button to apply your script</p>
</aside>
<article>
<div class="card">
<form action="" method="post">
<input type="hidden" name="action_type" value ="create_script">
<button type="submit">Crear Script tag</button>
</form>
</div>
</article>
</section>
<section >
<aside>
<h2> Delete script tag </h2>
<p>click install button to apply your script</p>
</aside>
<article>
<div class="card">
<form action="" method="post">
<input type="hidden" name="action_type" value ="delete_script">
<button type="submit">Borrar Script tag</button>
</form>
</div>
</article>
</section>
<?php include_once("footer.php")?>