var ga_exist = false;
console.log('GA: ' + typeof ga);
if (typeof ga == "undefined") {
console.log('GA is not function and not detected');
}
$(".btn-product-details").click(function(e) {
var raw_data = $(this).closest(".item_container").attr("data-json");
if (!is_undef(raw_data) && raw_data != '') {
if (e.preventDefault) e.preventDefault();
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;
e.returnValue = false;
var raw_data = decodeURIComponent(raw_data);
var data = JSON.parse(raw_data);
ga('ec:addProduct', {
'id': data.id,
'name': data.model,
'category': data.categoryPath,
'brand': data.brand,
'prodType': data.prod_type,
'position': data.posIndex
});
ga('ec:setAction', 'click', {
'list': data.listType
});
var tmp_url = data.url;
if (ga.hasOwnProperty('loaded') && ga.loaded === true) {
ga('send', 'event', {
'eventCategory': 'UX',
'eventAction': 'productDetailsClick',
'eventLabel': tmp_url,
'eventValue': 1,
'hitCallback': function() {
console.log(tmp_url);
document.location = data.url;
}
});
} else {
console.log('No GA');
document.location = tmp_url;
}
}
});
$(document).ready(function() {
console.log('Ready GA: ' + typeof ga);
ga_exist = (typeof ga === "function");
$('.catalog_item .item_container').each(function() {
var raw_data = $(this).attr("data-json");
if (!is_undef(raw_data) && raw_data != '') {
var raw_data = decodeURIComponent(raw_data);
var data = JSON.parse(raw_data);
ga('ec:addImpression', {
'id': data.id,
'name': data.model,
'category': data.categoryPath,
'brand': data.brand,
'prodType': data.prod_type,
'list': data.listType,
'position': data.posIndex
});
}
});
});
function ga_cart_remove(raw_data) {
if (!is_undef(raw_data) && raw_data != '') {
var raw_data = decodeURIComponent(raw_data);
var data = JSON.parse(raw_data);
console.log('remove data:', data);
ga('ec:addProduct', {
'id': data.id,
'name': data.model,
'price': data.price,
'brand': data.brand,
'category': data.categoryPath,
'prodType': data.prod_type,
'position': data.position,
'quantity': $("input[id=qty_" + data.id + ']').val()
});
ga("ec:setAction", "remove");
ga("send", "event", "UX", "click", "removeFromCart");
}
}
function ga_cart_add(raw_data) {
if (!is_undef(raw_data) && raw_data != '') {
var raw_data = decodeURIComponent(raw_data);
var data = JSON.parse(raw_data);
console.log('add data:', data);
var modalBox = $('#buyForm');
ga('ec:addProduct', {
'id': data.id,
'name': data.model,
'category': data.categoryPath,
'brand': data.brand,
'prodType': data.prod_type,
'price': data.price,
'quantity': $("input.prod_count", modalBox).val()
});
ga('ec:setAction', 'add');
ga('send', 'event', 'UX', 'click', 'addToCart');
}
}
function ga_order_preview() {
var is_cart_empty = 1;
$('.order_item').each(function() {
var raw_data = $(this).attr("data-json");
if (!is_undef(raw_data) && raw_data != '') {
var raw_data = decodeURIComponent(raw_data);
var data = JSON.parse(raw_data);
console.log('add data:', data);
ga('ec:addProduct', {
'id': data.id,
'name': data.model,
'price': data.price,
'brand': data.brand,
'category': data.categoryPath,
'prodType': data.prod_type,
'position': data.position,
'quantity': $("input[id=qty_" + data.id + ']').val()
});
is_cart_empty = 0;
}
});
if (is_cart_empty == 0)
ga("ec:setAction", "checkout", {
"step": 1
});
}
function ga_order_submit() {
var is_cart_empty = 1;
$('.order_item').each(function() {
var raw_data = $(this).attr("data-json");
if (!is_undef(raw_data) && raw_data != '') {
var raw_data = decodeURIComponent(raw_data);
var data = JSON.parse(raw_data);
console.log('add data:', data);
ga('ec:addProduct', {
'id': data.id,
'name': data.model,
'price': data.price,
'brand': data.brand,
'category': data.categoryPath,
'prodType': data.prod_type,
'position': data.position,
'quantity': $("input[id=qty_" + data.id + ']').val()
});
is_cart_empty = 0;
}
});
};
var cart_items = new Array();
var debug_cart = false;
debug_cart = true;
$(document).ready(function() {
$('.buy_button').on('click', function() {
var cart = $('#top-cart');
var modalBox = $('#buyForm');
if (!$(this).hasClass("btn-large") && !$(this).hasClass("btnBuy")) {
var imgtodrag = $(this).parent().parent('.img').find("img").eq(0);
}
if (typeof imgtodrag == 'object' && typeof imgtodrag.offset() !== 'undefined') {
var imgclone = imgtodrag.clone().offset({
top: imgtodrag.offset().top,
left: imgtodrag.offset().left
}).css({
'opacity': '0.5',
'position': 'absolute',
'height': '150px',
'width': '150px',
'z-index': '100'
}).appendTo($('body')).animate({
'top': cart.offset().top + 10,
'left': cart.offset().left + 10,
'width': 75,
'height': 75
}, 1000, 'easeInOutExpo');
setTimeout(function() {
cart.effect("shake", {
times: 2
}, 200);
}, 1500);
imgclone.animate({
'width': 0,
'height': 0
}, function() {
$(this).detach()
});
}
var prod_id = $(this).prop('lang');
console.log('prod_id:' + prod_id);
$("#prod_id", modalBox).val(prod_id);
var prod_count = 0;
if (typeof cart_items[prod_id] !== 'undefined') prod_count = parseInt(cart_items[prod_id]);
if (debug_cart) console.log(cart_items[prod_id] + 'prod_count:' + prod_count);
$("input.prod_count", modalBox).val(prod_count);
$('.plus', modalBox).click();
$(".tovar .title", modalBox).html('hfdhfg');
$(".total_prod", modalBox).html('hgjhgjghk');
update_count_basket(4, 54);
//save_cart($("#prod_id", modalBox).val(), $("input.prod_count", modalBox).val());
$(this).html('Купить еще');
if (ga_exist) {
var raw_data = $(this).closest(".item_container").attr("data-json");
ga_cart_add(raw_data);
}
});
$.mask.definitions['~'] = '[+-]';
$('.customerphone, .phone').mask('+380 (99) 999-99-99', {
completed: function() {
$("button, .btn", $(this).parent()).removeClass('disabled');
}
});
$('.phone_short').mask('(099)999-99-99', {
completed: function() {
$("button, .btn", $(this).parent()).removeClass('disabled');
}
});
$('#buy_back_call_submit').bind('click', function() {
var modalBox = $('#buyForm');
var prod_id = $("#prod_id", modalBox).val();
var phone_el = $("input[name=customerphone]", modalBox);
var tmp_phone = $(phone_el).val();
if (empty(tmp_phone)) {
$(phone_el).focus();
alert('Пожалуйста введите номер телефона!');
} else {
send_feedback(tmp_phone, 'prod_id:' + prod_id, {
'type': 'fastOrder'
});
}
if (debug_cart)
console.log(prod_id);
});
$('.fast_order_form .btn').bind('click', function() {
var modalBox = $('#buyForm');
var phone_el = $(".fast_order_form input[name=phone]");
var tmp_phone = $(phone_el).val();
var prod_id = $(this).prop('lang');
if (empty(tmp_phone)) {
$(phone_el).focus();
alert('Пожалуйста введите номер телефона!');
} else {
if (typeof ga == "function") ga('send', 'event', 'Карточка товара', 'Купить в 1 клик');
send_feedback(tmp_phone, 'prod_id:' + prod_id, {
'type': 'fastOrder'
});
}
});
});
function save_cart(prod_id, prod_count, sender) {
var cart = $('#top-cart');
var modalBox = $('#buyForm');
if (!sender) sender = modalBox;
cart_items[prod_id] = prod_count;
JsHttpRequest.query('hr_gate.php?test=500&r=' + Math.random(), {
'sp': "prod_in_basket",
'prod_id': prod_id,
'prod_count': prod_count
}, function(result, errors) {
if (errors) console.log('Errors: ' + errors);
if (result) {
if (debug_cart)
console.log(result);
if (result.prod_info) {
var prod = result.prod_info;
if (debug_cart) console.log(prod);
if (typeof prod === 'object') {
var modelTitle = ((prod.prod_type) ? prod.prod_type + '
' : '') + prod.brand + ' ' + prod.model;
$(".tovar .title", modalBox).html(modelTitle);
var tmp_count = parseInt($("input.prod_count", sender).val());
if (debug_cart) console.log('count: ' + tmp_count);
$(".total_prod", sender).html(format_money(tmp_count * parseFloat(prod.price)));
if (prod.photo_path) {
var photo = prod.photo_path;
if (debug_cart) console.log('photo: ' + photo);
$(".tovar img", modalBox).prop('src', photo);
}
}
}
if (result.count_prod && result.total_sum) {
update_count_basket(result.count_prod, result.total_sum);
}
}
}, true);
}
function update_count_basket(count, sum) {
console.log(count + ' s:' + sum);
var cart = $('#top-cart');
var modalBox = $('#buyForm');
if (count > 0) {
var sum_str = format_money(sum);
cart.find('.btn.btn-cart').addClass('not_empty');
cart.find('#top-cart-content').html('В корзине' + count + ' товар' + ((count > 4) ? 'ов' : ((count > 1) ? 'а' : '')) + '
на ' + sum_str + '
Корзина пуста
'); $(".cart_count", modalBox).html('--'); $(".cart_total").html('--'); } if (sum < 1000) var free_delivery = "Для бесплатной доставки осталось добавить в заказ товаров на " + format_money(1000 - sum) + " "; else var free_delivery = "Бесплатная доставка!!!"; $('.dostavka').html(free_delivery + '