Shopify app_bridge backwork compatibility
This commit is contained in:
parent
2eea6e4f23
commit
d0526c9c5b
3 changed files with 79 additions and 23 deletions
|
@ -485,7 +485,7 @@ class common_function {
|
||||||
$cbattrjspath = 'https://seers-application-assets.s3.amazonaws.com/scripts/cbattributes.js';
|
$cbattrjspath = 'https://seers-application-assets.s3.amazonaws.com/scripts/cbattributes.js';
|
||||||
$arrscriptexist = [false, false];
|
$arrscriptexist = [false, false];
|
||||||
|
|
||||||
|
|
||||||
//get all avialable tags
|
//get all avialable tags
|
||||||
$allscriptags = $this->prepare_api_condition(array('script_tags'), array(), 'GET', '0', $token, $shop);
|
$allscriptags = $this->prepare_api_condition(array('script_tags'), array(), 'GET', '0', $token, $shop);
|
||||||
|
|
||||||
|
@ -503,12 +503,12 @@ class common_function {
|
||||||
$arrscriptexist[1] = false;
|
$arrscriptexist[1] = false;
|
||||||
//remove the script
|
//remove the script
|
||||||
$scriptdel = $this->prepare_api_condition(array('script_tags', $thescript['id']), array(), 'DELETE', '0', $token, $shop);
|
$scriptdel = $this->prepare_api_condition(array('script_tags', $thescript['id']), array(), 'DELETE', '0', $token, $shop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($arrsrc as $sitind => $sitesrc) {
|
foreach ($arrsrc as $sitind => $sitesrc) {
|
||||||
|
|
||||||
if (!$arrscriptexist[$sitind]) {
|
if (!$arrscriptexist[$sitind]) {
|
||||||
|
@ -516,12 +516,12 @@ class common_function {
|
||||||
//add this src in scripts
|
//add this src in scripts
|
||||||
$scriptinsert = $this->prepare_api_condition(array('script_tags'), array('script_tag' => array( "event"=>"onload", "src"=>$sitesrc)), 'POST', '0', $token, $shop);
|
$scriptinsert = $this->prepare_api_condition(array('script_tags'), array('script_tag' => array( "event"=>"onload", "src"=>$sitesrc)), 'POST', '0', $token, $shop);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function plugin_active_inactive($shopdetail, $isative = 0){
|
public function plugin_active_inactive($shopdetail, $isative = 0){
|
||||||
$postData = array(
|
$postData = array(
|
||||||
'domain' => $shopdetail['shop'],
|
'domain' => $shopdetail['shop'],
|
||||||
|
@ -559,7 +559,7 @@ class common_function {
|
||||||
$response =json_decode($response, TRUE);
|
$response =json_decode($response, TRUE);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ if (isset($_REQUEST['shop']) && $_REQUEST['shop'] != "") {
|
||||||
$store_row = $cf_obj->select_row(TABLE_USER_STORES, $selected_field, $where);
|
$store_row = $cf_obj->select_row(TABLE_USER_STORES, $selected_field, $where);
|
||||||
|
|
||||||
if (isset($_GET['code'])) {
|
if (isset($_GET['code'])) {
|
||||||
|
$thehost = (!empty($_REQUEST['host']) ? $_REQUEST['host'] : "");
|
||||||
$url_param_arr = array('client_id' => SHOPIFY_API_KEY, 'client_secret' => SHOPIFY_SECRET, 'code' => $_GET['code']);
|
$url_param_arr = array('client_id' => SHOPIFY_API_KEY, 'client_secret' => SHOPIFY_SECRET, 'code' => $_GET['code']);
|
||||||
$responce = $cf_obj->prepare_api_condition(array('oauth', 'access_token'), $url_param_arr, 'POST', 0, '', $shop);
|
$responce = $cf_obj->prepare_api_condition(array('oauth', 'access_token'), $url_param_arr, 'POST', 0, '', $shop);
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ if (isset($_REQUEST['shop']) && $_REQUEST['shop'] != "") {
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'name' => mysqli_real_escape_string($cf_obj->db_connection, $shopinfo['name']), /* e.g example */
|
'name' => mysqli_real_escape_string($cf_obj->db_connection, $shopinfo['name']), /* e.g example */
|
||||||
'shop' => $shop, /* e.g example.myshopify.com */
|
'shop' => $shop, /* e.g example.myshopify.com */
|
||||||
|
'host' => $thehost,
|
||||||
'domain' => $shopinfo['domain'],
|
'domain' => $shopinfo['domain'],
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'owner' => $shopinfo['shop_owner'],
|
'owner' => $shopinfo['shop_owner'],
|
||||||
|
|
|
@ -1,17 +1,66 @@
|
||||||
<?php if (MODE == 'live') { ?>
|
<?php //if (MODE == 'live') { ?>
|
||||||
|
<?php echo ((!empty($current_user['host'])) ? '<script src="https://unpkg.com/@shopify/app-bridge@2.0.0"></script>' : "" ); ?>
|
||||||
<script src="https://cdn.shopify.com/s/assets/external/app.js"></script>
|
<script src="https://cdn.shopify.com/s/assets/external/app.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var query_output = '';
|
var hostval = "<?php echo ((!empty($current_user['host'])) ? $current_user['host'] : "" ); ?>";
|
||||||
ShopifyApp.init({
|
|
||||||
forceRedirect: true,
|
if (hostval) {
|
||||||
apiKey: '<?php echo SHOPIFY_API_KEY; ?>',
|
var AppBridge = window['app-bridge'];
|
||||||
shopOrigin: 'https://<?php echo $shop; ?>'
|
|
||||||
});
|
var createApp = AppBridge.createApp;
|
||||||
ShopifyApp.ready(function () {
|
var TitleBar = AppBridge.TitleBar;
|
||||||
ShopifyApp.Bar.initialize({
|
var Button = AppBridge.Button;
|
||||||
buttons: {
|
var actions = AppBridge.actions;
|
||||||
secondary: [{"label": "Dashboard", "href": "index.php?shop=<?php echo $shop; ?>"}]}
|
var Loading = actions.Loading;
|
||||||
|
}
|
||||||
|
|
||||||
|
var app = "";
|
||||||
|
var loading = "";
|
||||||
|
|
||||||
|
|
||||||
|
if (hostval) {
|
||||||
|
app = createApp({
|
||||||
|
apiKey: '<?php echo SHOPIFY_API_KEY; ?>',
|
||||||
|
host: '<?php echo ((!empty($current_user['host'])) ? $current_user['host'] : "" ); ?>',
|
||||||
|
shop: 'https://<?php echo $shop; ?>',
|
||||||
|
shopOrigin: 'https://<?php echo $shop; ?>',
|
||||||
|
forceRedirect: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
loading = Loading.create(app);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var query_output = '';
|
||||||
|
|
||||||
|
if (!hostval) {
|
||||||
|
|
||||||
|
ShopifyApp.init({
|
||||||
|
forceRedirect: true,
|
||||||
|
apiKey: '<?php echo SHOPIFY_API_KEY; ?>',
|
||||||
|
shopOrigin: 'https://<?php echo $shop; ?>'
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ShopifyApp.ready(function () {
|
||||||
|
if (!hostval) {
|
||||||
|
ShopifyApp.Bar.initialize({
|
||||||
|
buttons: {
|
||||||
|
secondary: [{"label": "Dashboard", "href": "index.php?shop=<?php //echo $shop; ?>"}]}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const dashboardButton = Button.create(app, { label: 'Dashboard', "href": "index.php?shop=<?php echo $shop; ?>" });
|
||||||
|
const titleBarOptions = {
|
||||||
|
buttons: {
|
||||||
|
secondary: dashboardButton,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const myTitleBar = TitleBar.create(app, titleBarOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var shopifyQL = 'SHOW ua_browser_version, ua_os, ua_form_factor, ua_os_version, ua_browser, referrer_host, page_type, page_path, page_url, page_resource_id, referrer_host, referrer_name, referrer_path, referrer_url, referrer_source, utm_campaign_content, utm_campaign_term, utm_campaign_medium, utm_campaign_source, utm_campaign_name, location_country, location_region, location_city OVER day(timestamp) AS day FROM visits SINCE -7d UNTIL today ORDER BY day ASC';
|
var shopifyQL = 'SHOW ua_browser_version, ua_os, ua_form_factor, ua_os_version, ua_browser, referrer_host, page_type, page_path, page_url, page_resource_id, referrer_host, referrer_name, referrer_path, referrer_url, referrer_source, utm_campaign_content, utm_campaign_term, utm_campaign_medium, utm_campaign_source, utm_campaign_name, location_country, location_region, location_city OVER day(timestamp) AS day FROM visits SINCE -7d UNTIL today ORDER BY day ASC';
|
||||||
//var shopifyQL = 'SELECT * FROM shopify.online_store_sessions';
|
//var shopifyQL = 'SELECT * FROM shopify.online_store_sessions';
|
||||||
var renderData = function (response) {
|
var renderData = function (response) {
|
||||||
|
@ -29,6 +78,11 @@
|
||||||
error: handleError
|
error: handleError
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ShopifyApp.Bar.loadingOff();
|
//ShopifyApp.Bar.loadingOff();
|
||||||
|
if (hostval) {
|
||||||
|
loading.dispatch(Loading.Action.STOP);
|
||||||
|
} else {
|
||||||
|
ShopifyApp.Bar.loadingOff();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php } ?>
|
<?php //} ?>
|
||||||
|
|
Loading…
Reference in a new issue