/*
*/
if (typeof GTS === 'undefined') {
console.log("%c init GTS ", "background: #1960bc; color: #fff", );
window.GTS = class GTS {
static publicLog(text) {
console.log("%c " + text, "background: #1960bc; color: #fff", );
}
static getStoreId() {
return Shopify.shop;
}
/**
*
* @param {number} amount
*/
static moneyFormat(money_format, amount) {
var price = amount / 100;
return String(money_format).replace('{{amount}}', price.toFixed(2)) + '';
}
static log(text) {
var debug = localStorage.getItem("debug");
if (debug == true) {
console.log(text);
}
}
static warn(text) {
var debug = localStorage.getItem("debug");
if (debug == true) {
console.warn(text);
}
}
static debug(val = true) {
localStorage.setItem("debug", val);
}
static getIterateChild(lastElement) {
var lastChild = lastElement.find('div,span');
if (lastChild.length) {
lastElement = this.getIterateChild(lastChild);
}
return lastElement;
}
static isMobile() {
if (window.innerWidth <= 800 && window.innerHeight <= 800) {
return true;
} else {
return false;
}
}
static loadLink(url) {
jQuery('head').append('');
}
static loadScriptList(app) {
GTS.log('loadScriptList');
if ((typeof jQuery === 'undefined')) {
GTS.loadScript('https://cdn.shopify.com/s/files/1/0020/7624/6127/t/8/assets/jquery-2.2.3.min.js', function() {
//window.GTS.jQuery191 = jQuery.noConflict(true);
// GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js');
// GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/cart.min.js');
// GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/rivets-cart.min.js');
// GTS.loadScript('//rafaelcastrocouto.github.io/jQuery.DomOutline/demo/jquery.dom-outline-1.0.js');
app.myAppJavaScript(jQuery);
});
} else if ((parseFloat(jQuery.fn.jquery) < 1.7)) {
GTS.loadScript('https://cdn.shopify.com/s/files/1/0020/7624/6127/t/8/assets/jquery-2.2.3.min.js', function() {
window.GTS.jQuery191 = jQuery.noConflict(true);
// GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js');
// GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/cart.min.js');
// GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/rivets-cart.min.js');
// GTS.loadScript('//rafaelcastrocouto.github.io/jQuery.DomOutline/demo/jquery.dom-outline-1.0.js');
app.myAppJavaScript(window.GTS.jQuery191);
});
} else {
GTS.loadScript('//code.jquery.com/ui/1.12.1/jquery-ui.min.js');
GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/cart.min.js');
GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/rivets-cart.min.js');
GTS.loadScript('//rafaelcastrocouto.github.io/jQuery.DomOutline/demo/jquery.dom-outline-1.0.js');
app.myAppJavaScript(jQuery);
}
}
static loadScript(url, callback) {
if (callback == undefined) {
callback = function() {}
}
var script = document.createElement('script');
script.type = 'text/javascript';
// If the browser is Internet Explorer.
if (script.readyState) {
script.onreadystatechange = function() {
if (script.readyState === 'loaded' || script.readyState === 'complete') {
script.onreadystatechange = null;
callback();
}
};
// For any other browser.
} else {
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
static getLocalDayHour() {
var date = new Date();
return date.getDate() + '-' + date.getHours();
}
static checkCart() {
if (window.GTS.cart != undefined) {
return;
}
$("head").append('');
var elem = $('meta[name="gts_cart:count"]');
window.GTS.cart = { item_count: 0 };
setInterval(function() {
jQuery.getJSON('/cart.js', function(cart) {
if (window.GTS.cart.item_count != cart.item_count) {
window.GTS.cart = cart;
elem.attr('content', cart.item_count);
}
});
}, 1000);
}
}
}
class GTQD {
static redirect(location, args) {
var form = '';
jQuery.each(args, function(key, value) {
form += '';
});
jQuery('
').appendTo('body').submit();
}
static cartUpdate(product_key, cnt) {
var pid = product_key.trim();
var params = {
quantity: cnt,
id: pid
};
GTS.log('change');
jQuery.ajax({
type: "POST",
url: "/cart/change.js",
data: params
}).always(function() {
window.location.reload();
});
//return location.reload(true);
}
static showCartDiscounts(data) {
var discounts = data.discounts;
var path = JSON.parse(data.path);
var flag = 0;
var setForm = setInterval(function() {
var formSelector = 'form[action="/cart"], form[action="/checkout"] ';
if (path.form !== undefined) {
formSelector = path.form;
}
var form = jQuery(formSelector);
GTS.log(formSelector);
if (form.length > 0) {
GTS.log('+++ showCartDiscounts > form exist: ' + formSelector);
clearInterval(setForm);
} else {
GTS.log('--- showCartDiscounts > form not exist: ' + formSelector);
}
if (path.unbind_form !== undefined) {
console.log('QD submitCheckout bind');
form.attr('onsubmit', "GTQD.submitCheckout();return false;");
window.gtapps_qd.unbind_form = true;
}
form.each(function(i, formObj) {
var rowSelector = path.row;
var rows = jQuery(formObj).find(rowSelector);
GTS.log(data);
GTS.log(formSelector + ' -> find ->' + rowSelector);
if (rows.length > 0) {
GTS.log('+++ showCartDiscounts > row exist: ' + rowSelector);
clearInterval(setForm);
} else {
GTS.log('--- showCartDiscounts > row not exist: ' + rowSelector);
}
rows.each(function(i) {
var lastElement = jQuery(this).find(path.price);
var line_price = jQuery(this).find('.gtapps-cart-item-line-price');
if (line_price.length) {
//line_price.html('');
GTS.log('---length-----');
lastElement = line_price;
} else if (path.price_final !== undefined) {
lastElement.addClass('gtapps-cart-item-line-price');
} else {
lastElement = GTS.getIterateChild(lastElement);
lastElement.addClass('gtapps-cart-item-line-price');
}
var cart_item = window.gtapps_qd.cart.items[i];
//GTS.log(cart_item);
if (cart_item !== undefined) {
lastElement.attr('qd-data-key', cart_item.key);
GTS.log(discounts.upsell.items[cart_item.key]);
if (discounts.upsell.items[cart_item.key] != undefined) {
var upsell_message = discounts.upsell.items[cart_item.key].message;
jQuery(this).find('.qd6_upsell').remove();
if (upsell_message != undefined) {
jQuery(this).find(path.upsell).after(upsell_message);
}
}
} else {
GTS.log('window.gtapps_qd.cart.items[i] == undefined ');
}
discounts.cart.items.forEach(function(item) {
if (cart_item == undefined) {
GTS.log('cart_item == undefined');
return;
}
if (item.key != cart_item.key) {
GTS.log('item.key != cart_item.key');
return;
}
GTS.log("GTQD:gtappsShowCartDiscounts - original_line_price - " + item.original_line_price);
GTS.log("GTQD:gtappsShowCartDiscounts - discounted_line_price - " + item.discounted_line_price);
GTS.log("GTQD:key - " + item.key);
if (item.discounted_line_price < item.original_line_price) {
GTS.log("GTQD:gtappsShowCartDiscounts - add discont " + item.key);
flag = 1;
jQuery(".gtapps-cart-item-line-price[qd-data-key='" + item.key + "']")
.html("" + GTS.moneyFormat(discounts.money_format, item.original_line_price) + "
" +
"" + GTS.moneyFormat(discounts.money_format, item.discounted_line_price) + "")
} else {
GTS.log("GTQD:gtappsShowCartDiscounts - not discont");
jQuery(".gtapps-cart-item-line-price[qd-data-key='" + item.key + "']").html("" + GTS.moneyFormat(discounts.money_format, item.original_line_price) + "")
}
//jQuery(".gtapps-cart-item-line-price[data-key='" + item.key + "']").removeAttr("data-key"); //.removeClass("gtapps-cart-item-line-price")
});
});
});
GTS.log("GTQD:subtotal FLAG - " + flag);
if (flag == 1) {
GTS.log("GTQD:subtotal - " + path.subtotal);
jQuery(path.subtotal).html("" + GTS.moneyFormat(discounts.money_format, discounts.original_price_total) + "" +
"
" + GTS.moneyFormat(discounts.money_format, discounts.discounted_price_total) + "");
window.gtapps_qd.discounted_price_total = discounts.discounted_price_total;
if (path.hide != undefined) {
jQuery(path.hide).hide();
}
GTQD.bindCheckoutBtn(path.checkout, function(checkoutBtn) {
console.log("GTQD.bindCheckoutBtn callback set");
if (data.code != undefined && data.code.path.status == true) {
if (jQuery('#qd-discount-code-form').length == 0) {
jQuery(
'').insertAfter(data.code.path.placement);
jQuery("#qd-discount-btn").click(function(e) {
let code = jQuery("#qd-discount-code").val();
if (code.length > 0) {
window.gtapps_qd.code = code;
jQuery("#qd-discount-code-tag").html(code);
new GTcart().initCart();
}
return false;
});
}
jQuery("#qd-discount-code-tag").html(data.code.apply);
}
});
} else {
jQuery("#qd-discount-code-form").remove();
}
}, 1000);
}
static checkoutDisabled(active) {
jQuery("input[name='checkout']:not(.gtapps-ignore), input[value='Checkout']:not(.gtapps-ignore), button[name='checkout']:not(.gtapps-ignore), [href$='checkout']:not(.gtapps-ignore), button[value='Checkout']:not(.gtapps-ignore), input[name='goto_pp'], button[name='goto_pp'], input[name='goto_gc'], button[name='goto_gc'],.gtapps_checkout")
.attr('disabled', active);
}
static bindCheckoutBtn(selector, callback) {
var checkoutSeector = "button:contains('Checkout'),a[href='/checkout'],input[name='checkout']:not(.gtapps-ignore), input[value='Checkout']:not(.gtapps-ignore), button[name='checkout']:not(.gtapps-ignore), [href$='checkout']:not(.gtapps-ignore), button[value='Checkout']:not(.gtapps-ignore), input[name='goto_pp'], button[name='goto_pp'], input[name='goto_gc'], button[name='goto_gc'],.gtapps_checkout";
if (selector != undefined) {
checkoutSeector = selector;
}
GTS.log('GTQD::bindCheckoutBtn');
console.log(checkoutSeector);
let checkoutBtnArr = jQuery(checkoutSeector);
if (checkoutBtnArr.length < 1) {
GTS.log(checkoutBtnArr.length);
GTS.warn('checkoutBtn.length != 1');
}
checkoutBtnArr.each(function(index) {
let checkoutBtn = jQuery(this)
let copyBtn = checkoutBtn.next("#gd3_copy_checkout:first");
GTS.log(checkoutBtn.attr('type'));
if (checkoutBtn.attr('type') == "submit" || checkoutBtn.attr('type') == undefined || checkoutBtn.attr('type') == "button") {
console.log("type submit");
console.log(copyBtn);
if (copyBtn.length == 0) {
console.log("copyBtn undefined");
let val_text = checkoutBtn.val();
let btn_text = checkoutBtn.html();
console.log(checkoutBtn);
console.log(val_text);
console.log(btn_text);
if (val_text != '') {
//copyBtn.val(val_text);
if (btn_text == '') {
btn_text = val_text;
}
}
checkoutBtn.after("");
jQuery("#qd-discount-btn").attr("class", checkoutBtn.attr('class'));
checkoutBtn.hide();
copyBtn = checkoutBtn.next("#gd3_copy_checkout:first");
}
}
console.log("111111-1");
console.log(copyBtn);
if (typeof callback === 'function') {
callback(checkoutBtn);
}
if (copyBtn.length != 0) {
checkoutBtn = copyBtn;
}
checkoutBtn.unbind("click");
if (typeof callback === 'function') {
callback(checkoutBtn);
}
if (window.gtapps_qd.unbind_form !== undefined) {
GTS.log('unbind_form');
checkoutBtn.unbind("submit").unbind('click').click(function(e) {
console.log('33 click 1');
e.preventDefault();
GTQD.submitCheckout();
return false;
});
return;
}
checkoutBtn.click(function(e) {
console.log('33 click 1');
e.preventDefault();
console.log('33 click 2');
GTS.log('GTQD::bindCheckoutBtn click');
var url = window.gtapps_qd.vd_url + "discount/create_draft_order?store_id=" + window.gtapps_qd.store_id;
GTQD.redirect(url, {
'cart_json': JSON.stringify(window.gtapps_qd.cart),
'currency': Shopify.currency.active,
'currency_rate': Shopify.currency.rate,
'code': window.gtapps_qd.code,
customer: window.gtapps_qd.customer
});
return false;
});
});
}
static submitCheckout() {
console.log('QD submitCheckout');
var url = window.gtapps_qd.vd_url + "discount/create_draft_order?store_id=" + window.gtapps_qd.store_id;
GTQD.redirect(url, {
'cart_json': JSON.stringify(window.gtapps_qd.cart),
'currency': Shopify.currency.active,
'currency_rate': Shopify.currency.rate,
'code': window.gtapps_qd.code,
customer: window.gtapps_qd.customer
});
return false;
}
static bindCheckoutToElement(element) {
GTS.log('GTQD::bindCheckoutToElement');
jQuery(element).on('click', function(e) {
e.preventDefault();
GTQD.submitCheckout();
});
}
}
/**
* main obj
*/
GTQ = function() {
this.init = function() {
GTS.log('init 0t');
if (window.gtapps_qd == undefined) {
GTS.log('init 1');
window.gtapps_qd = {
store_id: Shopify.shop,
cart: null,
is_volume_discount: null,
product_id: null,
page_type: null,
vd_url: "https://qd2.tengrowth.com/",
customer: null,
is_volume_discount_upgraded: true,
is_volume_discount: true,
discounted_price_total: 0,
code: '',
data: ''
}
if (meta.page.customerId != undefined) {
window.gtapps_qd.customer = meta.page.customerId;
}
GTS.log('gt::init 2');
setPageType();
GTS.loadScriptList(this);
}
}
setPageType = function() {
//GTS.log('gt::setPageType');
window.gtapps_qd.page_type = meta.page.pageType
if (window.gtapps_qd.page_type == 'product') {
window.gtapps_qd.product_id = meta.product.id;
} else if (window.gtapps_qd.page_type == 'home') {
window.gtapps_qd.page_type = 'home';
} else if (window.location.pathname == '/cart') {
window.gtapps_qd.page_type = 'cart';
} else if (typeof ShopifyPay !== "undefined") {
window.gtapps_qd.page_type = 'checkouts';
}
}
/**
*
* @param {*} $
*/
this.myAppJavaScript = function($) {
GTS.log('GT:myAppJavaScript:' + window.gtapps_qd.page_type);
if (window.gtapps_qd.page_type == 'product') {
new GTproduct().init();
} else if (window.gtapps_qd.page_type == 'home') {
new GTproduct().init();
} else if (window.gtapps_qd.page_type == 'cart') {
new GTcart().init();
}
new GTcartAjax().init();
}
}
GTcartAjax = function() {
this.init = function() {
jQuery.ajax({
type: "GET",
url: window.gtapps_qd.vd_url + "theme/ajax-cart",
data: {
name: Shopify.theme.name,
store_id: window.gtapps_qd.store_id,
customer: window.gtapps_qd.customer
},
crossDomain: true,
dataType: 'json',
success: function(data) {
cart = JSON.parse(data);
if (cart.active == 'true') {
if (cart.hideOnCart != undefined && cart.hideOnCart == 'true' && window.gtapps_qd.page_type == 'cart') {
GTS.log('GTcartAjax -> hideOnCart');
return;
}
if (cart.css != undefined) {
console.log(window.gtapps_qd.vd_url + cart.css);
GTS.loadLink(window.gtapps_qd.vd_url + cart.css);
}
jQuery(document).click(function() {
setTimeout(function() {
new GTcartAjax().initCart(cart.form);
}, 1000);
});
jQuery("a[href='/cart']").click(function() {
setTimeout(function() {
new GTcartAjax().initCart(cart.form);
}, 1000);
});
jQuery(document).ajaxComplete(function(event, xhr, settings) {
//console.warn(settings.url);
if (settings.url == '/cart/add.js') {
new GTcartAjax().initCart(cart.form);
}
});
(function(ns, fetch) {
if (typeof fetch !== 'function') return;
ns.fetch = function() {
var out = fetch.apply(this, arguments);
if (arguments[0] == "/cart/add.js") {
new GTcartAjax().initCart(cart.form);
}
return out;
}
}(window, window.fetch))
new GTcartAjax().initCart(cart.form);
}
}
});
}
this.initCart = function(form) {
GTS.log('GTcartAjax -> initCart');
jQuery.getJSON('/cart.js', function(cart) {
window.gtapps_qd.cart = cart;
if (typeof window.gtapps_qd.cart.items == "object") {
window.gtapps_qd.cart_collections = {};
for (var i = 0; i < window.gtapps_qd.cart.items.length; i++) {
["sku", "grams", "vendor", "url", "image", "handle", "requires_shipping", "product_type", "product_description"].map(function(a) {
delete window.gtapps_qd.cart.items[i][a]
});
window.gtapps_qd.cart_collections["v" + window.gtapps_qd.cart.items[i]['variant_id']] = [];
window.gtapps_qd.cart_collections["v" + window.gtapps_qd.cart.items[i]['variant_id']].push(window.gtapps_qd.cart.items[i].product_id);
}
}
cart_details(window.gtapps_qd.cart, form);
});
}
function cart_details(cart, form) {
GTS.log('GTcartAjax -> cart_details');
if (form == undefined) {
form = 'form[action="/cart"],.cart-wrapper a[href="/cart"], form[action="/checkout"]';
var form_mark = 'form[action="/cart"] .gtapps-cart-item-line-price,.cart-wrapper a[href="/cart"] .gtapps-cart-item-line-price, form[action="/checkout"] .gtapps-cart-item-line-price';
} else {
var form_mark = form + " .gtapps-cart-item-line-price";
}
GTS.log(form);
var formExist = jQuery(form).length;
if (!formExist) {
GTS.log('GTcartAjax -> cart_details -> form not exist');
return;
}
var cart_data = JSON.stringify(cart);
var form_edit = jQuery(form_mark).length;
if (cart_data == window.gtapps_qd.form_cart_data && form_edit > 0) {
console.log(form_edit);
GTS.log('GTcartAjax -> cart_details -> cart_data not edit');
return;
}
GTS.log('GTcartAjax::cart_details');
jQuery.ajax({
type: "POST",
url: window.gtapps_qd.vd_url + "discount/get_ajax_cart_details",
data: {
cart_data: JSON.stringify(cart.items),
store_id: window.gtapps_qd.store_id,
theme: Shopify.theme.name,
currency: Shopify.currency.active,
currency_rate: Shopify.currency.rate,
customer: window.gtapps_qd.customer
},
crossDomain: true,
dataType: 'json',
success: function(data) {
window.gtapps_qd.form_cart_data = JSON.stringify(cart);
if (data) {
json = JSON.parse(data);
if (json.error != undefined) {
return;
}
if (json.action != undefined) {
GTQD.cartUpdate(json.key, json.cnt);
}
window.gtapps_qd.cart_details_data = json
gtappsDoActions(data);
} else {
window.gtapps_qd.cart_details_data = nil
}
}
});
}
this.get_total = function(cart) {
jQuery.ajax({
type: "POST",
url: window.gtapps_qd.vd_url + "discount/get_ajax_cart_details",
data: {
cart_data: JSON.stringify(cart.items),
store_id: window.gtapps_qd.store_id,
theme: Shopify.theme.name,
currency: Shopify.currency.active,
currency_rate: Shopify.currency.rate,
customer: window.gtapps_qd.customer
},
crossDomain: true,
dataType: 'json',
success: function(data) {
window.gtapps_qd.form_cart_data = JSON.stringify(cart);
if (!data) {
GTS.log('GTcartAjax::get_total > data empty');
return;
}
data = JSON.parse(data);
if (json.error != undefined) {
return;
}
if (typeof data.discounts == "object") {
window.gtapps_qd.discounted_price_total = data.discounts.discounted_price_total;
}
}
});
}
function gtappsDoActions(data) {
GTS.log('GTcartAjax::gtappsDoActions');
if (!data) {
GTS.log('GTcartAjax::gtappsDoActions > data empty');
return;
}
data = JSON.parse(data);
GTS.log(data.discounts);
if (typeof data.discounts == "object" &&
typeof data.discounts.cart == "object" &&
typeof data.discounts.cart.items == "object") {
GTQD.showCartDiscounts(data)
}
let path = JSON.parse(data.path);
window.gtapps_qd.unbind_form = path.unbind_form;
GTQD.bindCheckoutBtn(path.checkout);
}
}
GTcart = function() {
this.init = function() {
GTS.log('GTcart::init');
if (window.gtapps_qd.page_type != "cart") {
GTS.log('GTcart::init finish');
return;
}
new GTcart().initCart();
//jQuery(document).click(function() {new GTcart().initCart();});
}
function cart_details(cart) {
let data = {
cart_data: JSON.stringify(cart.items),
store_id: window.gtapps_qd.store_id,
theme: Shopify.theme.name,
currency: Shopify.currency.active,
currency_rate: Shopify.currency.rate,
customer: window.gtapps_qd.customer,
code: window.gtapps_qd.code
};
if (window.gtapps_qd.data != undefined && window.gtapps_qd.data == data) {
console.log("cart_details data exist");
return;
}
window.gtapps_qd.data = data;
GTS.log('GTcart::cart_details');
jQuery.ajax({
type: "POST",
url: window.gtapps_qd.vd_url + "discount/get_cart_details",
data: data,
crossDomain: true,
dataType: 'json',
success: function(data) {
GTS.log('GTcart::cart_details ready');
setTimeout(function() {
jQuery('.gtapps_checkout').attr('disabled', false);
GTS.log(data);
if (data) {
json = JSON.parse(data);
if (json.action != undefined) {
GTQD.cartUpdate(json.key, json.cnt);
}
GTS.log(json.css);
window.gtapps_qd.cart_details_data = json
jQuery('head').append('');
gtappsDoActions(data);
jQuery(document).click(function() {
setTimeout(function() {
new GTcart().initCart();
}, 1000);
});
} else {
window.gtapps_qd.cart_details_data = nil
}
}, 1)
}
});
}
this.initCart = function() {
GTS.log('GTcart::init_cart');
jQuery.getJSON('/cart.js', function(cart) {
window.gtapps_qd.cart = cart;
if (typeof window.gtapps_qd.cart.items == "object") {
window.gtapps_qd.cart_collections = {};
for (var i = 0; i < window.gtapps_qd.cart.items.length; i++) {
["sku", "grams", "vendor", "url", "image", "handle", "requires_shipping", "product_type", "product_description"].map(function(a) {
delete window.gtapps_qd.cart.items[i][a]
});
window.gtapps_qd.cart_collections["v" + window.gtapps_qd.cart.items[i]['variant_id']] = [];
window.gtapps_qd.cart_collections["v" + window.gtapps_qd.cart.items[i]['variant_id']].push(window.gtapps_qd.cart.items[i].product_id);
}
}
cart_details(cart);
});
}
function gtappsDoActions(data) {
GTS.log('GTcart::gtappsDoActions');
if (data) {
data = JSON.parse(data);
GTS.log(data.discounts);
if (typeof data.discounts == "object" && typeof data.discounts.cart == "object" && typeof data.discounts.cart.items == "object") {
GTQD.showCartDiscounts(data);
}
}
}
}
GTproduct = function() {
this.init = function() {
var price = 1;
if (window.gtapps_qd.page_type == 'product') {
price = meta.product.variants[0].price
}
jQuery.ajax({
type: "GET",
dataType: "json",
url: window.gtapps_qd.vd_url + "discount/",
data: {
pid: window.gtapps_qd.product_id,
store_id: window.gtapps_qd.store_id,
theme: Shopify.theme.name,
price: price,
currency: Shopify.currency.active,
currency_rate: Shopify.currency.rate,
customer: window.gtapps_qd.customer
},
crossDomain: true,
success: function(data) {
GTS.log(data);
if (data != '') {
GTS.log(data);
var res = JSON.parse(data);
if (res.error != undefined) {
GTS.log(res.error);
return
}
var pathObj = JSON.parse(res.path);
var path = '.product__price,.product-price';
let insert = 'after';
if (pathObj.insert != undefined) {
insert = pathObj.insert;
}
if (pathObj.price != undefined) {
path = pathObj.price;
}
if (pathObj.css != undefined) {
GTS.loadLink(window.gtapps_qd.vd_url + pathObj.css);
}
if (pathObj.show_express = undefined) {
jQuery('.shopify-payment-button').hide();
}
GTS.log(path);
jQuery('head').append('');
console.log(res.html);
if (insert == 'after') {
jQuery(res.html).insertAfter(path);
} else {
jQuery(res.html).insertBefore(path);
}
action_btn_buy(res.btn_buy);
}
}
});
jQuery.ajax({
type: "GET",
dataType: "json",
url: window.gtapps_qd.vd_url + "discount/css",
data: {
store_id: window.gtapps_qd.store_id
},
crossDomain: true,
success: function(data) {
GTS.log(data);
if (data != '') {
GTS.log(data);
var res = JSON.parse(data);
if (res.error != undefined) {
GTS.log(res.error);
return
}
jQuery('head').append('');
}
}
});
}
function action_btn_buy(btn_buy) {
if (btn_buy.status != 1) {
return '';
}
let btn_buy_class = jQuery(btn_buy.placement).attr('class');
jQuery("")
.insertAfter(btn_buy.placement);
jQuery("#gtqd_checkout").on('click', function(e) {
e.preventDefault();
let cnt = jQuery("input[name='quantity']").val();
let variant_id = jQuery("select[name='id'],select[name='id']").children("option:selected").val();
if (variant_id == undefined) {
variant_id = jQuery("input[name='id']").val();
}
if (variant_id != undefined) {
jQuery.ajax({
type: "POST",
url: "/cart/add.js",
data: {
quantity: cnt,
id: variant_id
}
}).always(function() {
jQuery.getJSON('/cart.js', function(cart) {
window.gtapps_qd.cart = cart;
GTQD.submitCheckout();
});
});
}
});
}
}
new GTQ().init();