This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
/
ajax_saveConfiguration.php
127 lines (102 loc) · 3.83 KB
/
ajax_saveConfiguration.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
session_start();
require __DIR__.'/db.php';
require __DIR__.'/vendor/autoload.php';
use phpish\shopify;
require __DIR__.'/conf.php';
if (isset($_POST['domain_api_key']) && isset($_POST['api_token']) && isset($_SESSION['oauth_token'])) {
$shopify = shopify\client($_SESSION['shop'], SHOPIFY_APP_API_KEY, $_SESSION['oauth_token']);
$newDomain = $_POST['domain'];
$newDomainApiKey = $_POST['domain_api_key'];
$newApiToken = $_POST['api_token'];
$changeStatus = (isset($_POST['changeStatus']) ? true : false);
$newHelpPages = $_POST['help_pages'];
$newAddToCart = $_POST['qs_add_to_cart'];
$newVariation = $_POST['qs_variation'];
$newAddToWishlist = $_POST['qs_add_to_wishlist'];
$newImage = $_POST['qs_image'];
$newReview = $_POST['qs_review'];
$newPrice = $_POST['qs_price'];
$response = updateShopDetails($conn, $_SESSION['shop'], $_SESSION['oauth_token'], $newDomain, $newDomainApiKey, $newApiToken, $changeStatus, $newHelpPages, $newAddToCart, $newVariation, $newAddToWishlist, $newImage, $newReview, $newPrice);
try
{
$shop = getShopDetails($conn, $_SESSION['shop']);
$res = array();
if ($shop['status']) {
// enable Retargeting App
// base embedding
$scriptTag = array(
'script_tag' => array(
'event' => 'onload',
'src' => 'https://retargeting.biz/shopify/js/embedd.php'
)
);
$res[] = $shopify('POST /admin/script_tags.json', $scriptTag);
// triggers
$scriptTag = array(
'script_tag' => array(
'event' => 'onload',
'src' => 'https://retargeting.biz/shopify/js/triggers.php'
)
);
$res[] = $shopify('POST /admin/script_tags.json', $scriptTag);
// add Order/Create Webhook
$webhook = array(
'webhook' => array(
'topic' => 'orders/create',
'address' => 'https://retargeting.biz/shopify/webhooks/orders/create.php',
'format' => 'json'
)
);
$res[] = $shopify('POST /admin/webhooks.json', $webhook);
} else {
// disable Retargeting App
$stBase = null;
$stTriggers = null;
// remove ScriptTags
$scriptTags = $shopify('GET /admin/script_tags.json');
$res[] = $scriptTags;
foreach ($scriptTags as $st) {
if ($st['src'] == 'https://retargeting.biz/shopify/js/embedd.php') {
$res[] = $shopify('DELETE /admin/script_tags/'.$st['id'].'.json');
}
if ($st['src'] == 'https://retargeting.biz/shopify/js/triggers.php') {
$res[] = $shopify('DELETE /admin/script_tags/'.$st['id'].'.json');
}
if ($st['src'] == 'https://shopify.cornelb.ro/shopify/js/embedd.php') {
$res[] = $shopify('DELETE /admin/script_tags/'.$st['id'].'.json');
}
if ($st['src'] == 'https://shopify.cornelb.ro/shopify/js/triggers.php') {
$res[] = $shopify('DELETE /admin/script_tags/'.$st['id'].'.json');
}
}
// remove Order/Create Webhook
$webhooks = $shopify('GET /admin/webhooks.json');
$res[] = $webhooks;
foreach ($webhooks as $wh) {
if ($wh['address'] == 'https://retargeting.biz/shopify/webhooks/orders/create.php') {
$res[] = $shopify('DELETE /admin/webhooks/'.$wh['id'].'.json');
}
}
}
}
catch (shopify\ApiException $e)
{
# HTTP status code was >= 400 or response contained the key 'errors'
$response['kraken'] = $e;
$response['kraken'] = print_r($e->getRequest(), true);
$response['kraken'] = print_r($e->getResponse(), true);
}
catch (shopify\CurlException $e)
{
# cURL error
$response['kraken'] = $e;
$response['kraken'] = print_r($e->getRequest(), true);
$response['kraken'] = print_r($e->getResponse(), true);
}
$response['info'] = $res;
echo json_encode($response);
} else if (isset($_POST['disable_init']) && isset($_SESSION['oauth_token'])) {
$response = disableShopInit($conn, $_SESSION['shop'], $_SESSION['oauth_token']);
echo json_encode($response);
}