function occmAjaxPostAdd(uri, dataSet) {
$("#occm-form-container").find("input[type=text]").removeClass("error-in-input-text");
$.ajax({
url: uri,
type: 'post',
data: $(dataSet),
dataType: 'json',
success: function(json) {
var printR = function(o, printR) {
var c = 0;
if ('object' == typeof o) {
for (var i in o) {
c += printR(o[i], printR);
}
} else if ('string' == typeof o) {
alert(o);
c++;
}
return c;
};
if (json['error']) {
if ('string' == typeof json["error"]) {
if ("undefined" != typeof json["addErrorClass"] && json["addErrorClass"].length) {
for (var i in json["addErrorClass"]) {
$("#occm-form-container").find(json["addErrorClass"][i]).addClass("error-in-input-text");
}
}
alert(json['error']);
} else if ("object" == typeof json['error']) {
if (printR(json['error'], printR)) {
$.colorbox.close();
} else {
alert("Unexpected error, please, contact administrator agrovit.kuban@yandex.ru");
}
} else {
alert("Unexpected error, please, contact administrator agrovit.kuban@yandex.ru");
}
} else if (json['success']) {
alert(json['success']);
$.colorbox.close();
} else {
alert("Unexpected error, please, contact administrator agrovit.kuban@yandex.ru");
}
}
});
}
(function() {
$(document).ready(function() {
if (!$.colorbox) {
$("#button-cart").after('');
$("#button-cart").after('');
}
$("#button-cart").after('');
$("input.occm-button").click(function() {
$.ajax({
url: 'https://agrovit-bio.ru/index.php?route=module/occm/add',
type: 'post',
data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, information, .error, .text-danger').remove();
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
$('#option-' + i).after('' + json['error']['option'][i] + '');
}
}
if (json['error']['profile']) {
$('select[name="profile_id"]').after('' + json['error']['profile'] + '');
}
} else if (1 == json['success']) {
$.colorbox({
href: "https://agrovit-bio.ru/index.php?route=module/occm" + "&product_id=" + $("#button-cart").closest("div").find("input[name=product_id]").val(),
onComplete:function() {
$.colorbox.resize();
}
});
} else if (2 == json['success']) {
if (confirm('Подтвердить заказ')) {
occmAjaxPostAdd('https://agrovit-bio.ru/index.php?route=module/occm/add&occ_customer=1', '.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea');
}
}
}
});
return false;
});
});
$(document).on("click", "#occm-button-confirm", function() {
occmAjaxPostAdd('https://agrovit-bio.ru/index.php?route=module/occm/add', '[name^=\'occ_customer\'], .product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea');
return false;
});
})();