Shopify app_bridge backwork compatibility

This commit is contained in:
Seersco 2022-04-20 13:21:04 +05:00
parent 2eea6e4f23
commit d0526c9c5b
3 changed files with 79 additions and 23 deletions

View File

@ -485,7 +485,7 @@ class common_function {
$cbattrjspath = 'https://seers-application-assets.s3.amazonaws.com/scripts/cbattributes.js';
$arrscriptexist = [false, false];
//get all avialable tags
$allscriptags = $this->prepare_api_condition(array('script_tags'), array(), 'GET', '0', $token, $shop);
@ -503,12 +503,12 @@ class common_function {
$arrscriptexist[1] = false;
//remove the script
$scriptdel = $this->prepare_api_condition(array('script_tags', $thescript['id']), array(), 'DELETE', '0', $token, $shop);
}
}
}
}
}
foreach ($arrsrc as $sitind => $sitesrc) {
if (!$arrscriptexist[$sitind]) {
@ -516,12 +516,12 @@ class common_function {
//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);
}
}
}
}
}
public function plugin_active_inactive($shopdetail, $isative = 0){
$postData = array(
'domain' => $shopdetail['shop'],
@ -559,7 +559,7 @@ class common_function {
$response =json_decode($response, TRUE);
return $response;
}
}
}

View File

@ -32,6 +32,7 @@ if (isset($_REQUEST['shop']) && $_REQUEST['shop'] != "") {
$store_row = $cf_obj->select_row(TABLE_USER_STORES, $selected_field, $where);
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']);
$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,
'name' => mysqli_real_escape_string($cf_obj->db_connection, $shopinfo['name']), /* e.g example */
'shop' => $shop, /* e.g example.myshopify.com */
'host' => $thehost,
'domain' => $shopinfo['domain'],
'token' => $token,
'owner' => $shopinfo['shop_owner'],

View File

@ -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 type="text/javascript">
var query_output = '';
ShopifyApp.init({
forceRedirect: true,
apiKey: '<?php echo SHOPIFY_API_KEY; ?>',
shopOrigin: 'https://<?php echo $shop; ?>'
});
ShopifyApp.ready(function () {
ShopifyApp.Bar.initialize({
buttons: {
secondary: [{"label": "Dashboard", "href": "index.php?shop=<?php echo $shop; ?>"}]}
var hostval = "<?php echo ((!empty($current_user['host'])) ? $current_user['host'] : "" ); ?>";
if (hostval) {
var AppBridge = window['app-bridge'];
var createApp = AppBridge.createApp;
var TitleBar = AppBridge.TitleBar;
var Button = AppBridge.Button;
var actions = AppBridge.actions;
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 = 'SELECT * FROM shopify.online_store_sessions';
var renderData = function (response) {
@ -29,6 +78,11 @@
error: handleError
});
});
ShopifyApp.Bar.loadingOff();
//ShopifyApp.Bar.loadingOff();
if (hostval) {
loading.dispatch(Loading.Action.STOP);
} else {
ShopifyApp.Bar.loadingOff();
}
</script>
<?php } ?>
<?php //} ?>