if (strstr(site_url, "checkout", false) == "checkout") {
$(".c-cart-menu-close").html("");
location_flag = $("#hdn_location_flag").val();
}
$(window).load(function () {
$('[data-toggle="popover"]').popover();
});
/*$(document).ready(function () {
$("#demo").on("hide.bs.collapse", function () {
$(".Checkout-dropdown").html('{{"front_acc_newlogin"|trans}} ');
});
$("#demo").on("show.bs.collapse", function () {
$(".Checkout-dropdown").html('{{"front_acc_newlogin"|trans}} ');
});
});*/
var lastUrl = lastUrlSegment(site_url);
$("body").delegate(".addtocart", "click", function (e) {
if ($("#landingpagepopup").size() > 0) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
var custid = "";
custid = $("#hdn_custid").val();
var prdid = "";
var prdqty = 1;
var show_cart_popup = 1;
var commaseparated_attrid = "";
prdid = $(this).attr("data-name");
prdqty = $("#prdqty").val();
commaseparated_attrid = $("#commaseparated_attribute_id").val();
if (commaseparated_attrid == undefined) {
commaseparated_attrid = "";
}
var attr = $(this).attr("data-attribute");
if (typeof attr !== typeof undefined && attr !== false) {
commaseparated_attrid = attr;
}
if (prdqty == undefined) {
prdqty = 1;
}
if ($(this).hasClass("show-minicart")) {
show_cart_popup = 0;
}
var site_url1 = getBaseUrl();
if (
typeof productType != "undefined" &&
productType == 2 &&
commaseparated_attrid == ""
) {
swal("Warning!", "Please choose product options", "warning");
return false;
}
//BOF Tiered Calculation
var sel_tie_ids = sel_tie_qty = tie_discount = '';
var getsallqtys = [];
sel_tie_ids=$('.tcheckbx:checked').map(function() { if ($("#qty_"+this.id).val() > 0) return this.id;}).get().join(',');
sel_tie_qty=$('.tieqty').map(function() { getsallqtys.push($(this).val()); if (this.value > 0) return this.value;}).get().join(',');
//sel_tie_qty=$('.tieqty').map(function() { getsallqtys.push($(this).val());return this.value;}).get().join(',');
//tie_discount =$("#tie_discount").val();
tie_discount =$('#tieElement').data('tie-disc');
//If manually tried to change qty value to zero then shows an alert.
if(sel_tie_ids !='' && sel_tie_qty!=''){
if(checkAllQty(getsallqtys)){
$('.tcheckbx').each(function() {
this.checked = false;
});
$('.tieqty').each(function() {
this.value = 0;
});
showSwetAlert();
}
}
//var main_prod_id = $("#main_prod_id").val();
var main_prod_id = $('#tieElement').data('id');
var checkstatusArr = [0,2,3];
//EOF Tiered Calculation
if (prdid != "" && prdqty > 0) {
var forcetocart = '';
if (typeof $(this).data('forcetocart') !== 'undefined') {
forcetocart = $(this).data('forcetocart');
}
if(sel_tie_ids !='' && sel_tie_qty!=''){
$.ajax({
url: site_url1 + "/shoppingcart/addtocartTieProd",
type: "post",
data: "prdname=" + prdid + "&custid=" + custid + "&prdqty=" + prdqty + "&pn=hmc" + "&commaseparated_attrid=" + commaseparated_attrid + "&forcetocart=" + forcetocart + "&tieids=" + sel_tie_ids + "&tieqty=" + sel_tie_qty + "&tiedisc=" + tie_discount,
cache: false,
dataType: "json",
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function (result) {
$(".loader").removeClass("show");
$(".loader").addClass("hide");
var getresult= [];
getresult=result;
var statusFlag=0;
$.each(getresult, function(index, obj) {
// Access the 'status' property of each object
var status = obj.status;
//console.log("Status at index " + index + ": " + status);
if(status==2){
disabledMsg(index,2);
}
if(status==3){
disabledMsg(index,3);
}
if(status==0){
disabledMsg(index,0);
}
if(checkstatusArr.includes(Number(status))){
statusFlag=1;
}
if(index==main_prod_id && statusFlag==1){
$('.tcheckbx').each(function() {
this.checked = false;
this.disabled = true;
});
$('.tieqty').each(function() {
this.value = 0;
this.disabled = true;
});
}
if(index==main_prod_id && status==1){
if (result.abandonModal != 0) {
$("#abandoned_popup").show();
}
loadMiniCart(function () {
$("li.CartButton").addClass("open");
});
if (show_cart_popup == 0) {
$("li.CartButton").addClass("open");
setTimeout(function () {
$("li.CartButton").addClass("open");
}, 500);
}
}
if(typeof obj.gtaData != "undefined" && obj.gtaData != "" && wbGoogleAnalyticId != "" && wbStandardTracking == 1 && wbEcommerceTracking == 1){
var gtaArray = JSON.parse(obj.gtaData);
$.each(gtaArray, function(ind, item) {
gtag("event", "add_to_cart", {event_label: item.name,items: item});
});
}
});
if(statusFlag==1){
showSwetAlert();
}
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
}else{
$.ajax({
url: site_url1 + "/shoppingcart/addtocart",
type: "post",
data: "prdname=" + prdid + "&custid=" + custid + "&prdqty=" + prdqty + "&pn=hmc" + "&commaseparated_attrid=" + commaseparated_attrid + "&forcetocart=" + forcetocart,
cache: false,
dataType: "json",
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function (result) {
$(".loader").removeClass("show");
$(".loader").addClass("hide");
if (result.status == 1) {
//REN12
if (result.abandonModal != 0) {
$("#abandoned_popup").show();
}
loadMiniCart(function () {
$("li.CartButton").addClass("open");
});
if (show_cart_popup == 0) {
$("li.CartButton").addClass("open");
setTimeout(function () {
$("li.CartButton").addClass("open");
}, 500);
}
}else if(result.status == 2) {
var front_with_eta_for_this_product1 = front_with_eta_for_this_product.replace("%eta_date%",result.data).replaceAll('"','"');
swal(
{
title: front_shopping_cart_label,
text: front_with_eta_for_this_product1,
type: "warning",
showCancelButton: true,
confirmButtonText: "Continue",
cancelButtonText: "Cancel",
allowOutsideClick: true,
allowEscapeKey: true,
},
function(isConfirm) {
if (isConfirm) {
$('.addtocart[data-name=' + prdid + ']').attr("data-forcetocart","Y");
$('.addtocart[data-name=' + prdid + ']').trigger('click');
}
}
);
}else if(result.status == 3) {
var front_no_eta_for_this_product1 = front_no_eta_for_this_product.replaceAll('"','"');
swal(
{
title: front_shopping_cart_label,
text: front_no_eta_for_this_product1,
type: "warning",
allowOutsideClick: true,
allowEscapeKey: true,
},
function () {
}
);
}else {
var front_not_available_for_add_to_cart1 = front_not_available_for_add_to_cart.replaceAll('"','"');
swal(
{
title: front_shopping_cart_label,
text: front_not_available_for_add_to_cart1,
type: "warning",
allowOutsideClick: true,
allowEscapeKey: true,
},
function () {
}
);
}
if ( typeof result.gtaData != "undefined" &&
result.gtaData != "" &&
wbGoogleAnalyticId != "" &&
wbStandardTracking == 1 &&
wbEcommerceTracking == 1
) {
var gtaData = JSON.parse(result.gtaData);
gtag("event", "add_to_cart", {
event_label: gtaData.name,
items: result.gtaData,
});
}
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
}
}
});
$("body").delegate(".delcartitem", "click", function (e) {
e.preventDefault();
e.stopImmediatePropagation();
var checktype = "";
var prdids = $(this).attr("data-name");
var checktype = $(this).attr("data-type");
var prdqty = $(this).attr("data-qty");
var prdprc = $(this).attr("data-price");
var PAIds = $(this).attr("data-paids");
var prodattribute = $(this).attr("data-prodattribute");
var carttotalprice = $(".carttotalprice").attr("data-totprice");
var totalitem = $(".totalitem").html();
var totalcart = $(".totalcart").html();
if (parseInt(totalitem) > 0) {
totalitem = parseInt(totalitem) - 1;
$(".totalitem").html(parseInt(totalitem));
}
if (parseInt(totalcart) > 0) {
totalcart = parseInt(totalcart) - 1;
$(".totalcart").html(parseInt(totalcart));
if (parseInt(totalcart) == 0) {
$(".c-cart-menu").html(
'
'
);
$(".shopcartshiping").html(
'There is no any item in your shopping cart.
'
);
$(".btnqtyupdate").hide();
$(".btnshopcheckout").hide();
$(".totalcart").addClass("hide");
}
}
var totalprice = 0;
var total = 0;
total = prdqty * prdprc;
totalprice = parseFloat(carttotalprice) - parseFloat(total);
totalprice = parseFloat(totalprice).toFixed(2);
$(".carttotalprice").attr("data-totprice", parseFloat(totalprice));
var site_url1 = getBaseUrl();
$(".prodrow_" + prodattribute).remove();
if (prdids != "") {
$.ajax({
url: site_url1 + "/shoppingcart/removefromcart",
type: "post",
cache: false,
data:
"prdname=" +
prdids +
"&checkpackg="+
checktype+
"&prdprc=" +
parseFloat(total) +
"&totalprc=" +
parseFloat(carttotalprice) +
"&PAIds=" +
PAIds,
dataType: "json",
success: function (result) {
if (result.status == 1) {
loadMiniCart();
$(".carttotalprice").html(result.TotalPrice);
prtotal = $(".carttotalprice").html();
// $("#calculate_shipping_charge").trigger("click");
// updateshippingCharge();
var charge_symbol = 0;
var shipping_charge = 0;
if ($(".show_shipping_charge").length) {
shipping_charge = $(
"input:radio.show_shipping_charge:checked"
).attr("data-charge");
charge_symbol = $("input:radio.show_shipping_charge:checked").attr(
"data-charge-symbol"
);
}
var grandtotal = $(".shpsubtotal").attr("data-subtotal");
grandtotal = parseFloat(shipping_charge) + parseFloat(grandtotal);
grandtotal = grandtotal.toFixed(2);
$(".shpsubtotal").html(prtotal);
$("#shipping_charge").html(charge_symbol);
$(".shpgrdtotal").html(charge_symbol + grandtotal);
//$("#calculate_shipping_charge").trigger("click");
//updateshippingCharge();
//swal("Shopping Cart!", "Product deleted from Shopping Cart successfully", "success");
if (lastUrl == "checkout") {
window.location.href = site_url1 + "/" + lastUrl;
}
loadShopppingCart();
} else {
//swal("Shopping Cart!", "There is some issue in Shopping Cart", "info");
if (lastUrl == "checkout") {
window.location.href = site_url1 + "/" + lastUrl;
}
loadShopppingCart();
}
if (
result.gtaData != "" &&
wbGoogleAnalyticId != "" &&
wbStandardTracking == 1 &&
wbEcommerceTracking == 1
) {
var gtaData = JSON.parse(result.gtaData);
gtag("event", "remove_from_cart", {
event_label: gtaData.name,
items: result.gtaData,
});
}
/*$(".c-layout-page").css({
"margin-top": $(".c-layout-header").height() + "px",
});*/
/*if (result != "") {
var rs = result.split("||");
if (rs[2] != "" && wbGoogleAnalyticId != '' && wbStandardTracking == 1 && wbEcommerceTracking == 1) {
var gtaData = JSON.parse(rs[2]);
gtag('event', 'remove_from_cart', { "event_label": gtaData.name, "items": rs[2] });
}
$(".carttotalprice").html(rs[1]);
prtotal = $(".carttotalprice").html();
$("#calculate_shipping_charge").trigger("click");
updateshippingCharge();
var charge_symbol = 0;
var shipping_charge = 0;
if ($('.show_shipping_charge').length) {
shipping_charge = $("input:radio.show_shipping_charge:checked").attr('data-charge');
charge_symbol = $("input:radio.show_shipping_charge:checked").attr('data-charge-symbol');
}
var grandtotal = $(".shpsubtotal").attr('data-subtotal');
grandtotal = parseFloat(shipping_charge) + parseFloat(grandtotal);
grandtotal = grandtotal.toFixed(2);
$(".shpsubtotal").html(prtotal);
$("#shipping_charge").html(charge_symbol);
$(".shpgrdtotal").html(symbol + grandtotal);
$("#calculate_shipping_charge").trigger("click");
updateshippingCharge();
swal("Shopping Cart!", "Product deleted from Shopping Cart successfully", "success");
//window.location.href = site_url;
loadShopppingCart();
} else {
swal("Shopping Cart!", "There is some issue in Shopping Cart", "info");
//window.location.href = site_url;
loadShopppingCart();
}
return false;*/
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
}
return false;
});
$("body").delegate(".prdqtyup,.prdqtydown", "click", function (e) {
e.preventDefault();
e.stopImmediatePropagation();
var custid = "";
var prdid = "";
var prdqty = 1;
var prtotal = 0;
var prdprice = 0;
var newprice = 0;
custid = $("#hdn_custid").val();
index = $(this).attr("data-index");
prdqty = $(this).parent().prev(".prdqty").val();
prdid = $(this).attr("data-name");
prdprice = $(this).attr("data-price");
var PAIds = $(this).attr("data-paids");
var prodattribute = $(this).attr("data-prodattribute");
var commaseparated_attrid = $(this).attr("data-attribute");
$(".delcartitem[data-prodattribute='" + prodattribute + "']").attr(
"data-qty",
prdqty
);
if (commaseparated_attrid == undefined) {
commaseparated_attrid = "";
}
if (prdqty == undefined || prdqty < 1) {
prdqty = 1;
$(".c-item-" + index).val(prdqty);
return false;
}
var site_url1 = getBaseUrl();
if (prdid != "" && prdqty > 0) {
var forcetocart = '';
if (typeof $(".addtocart").data('forcetocart') !== 'undefined') {
forcetocart = $(this).attr("data-forcetocart");
}
$.ajax({
url: site_url1 + "/shoppingcart/addtocart",
type: "post",
cache: false,
data: "prdname=" + prdid + "&custid=" + custid + "&prdqty=" + prdqty + "&pn=sh" + "&PAIds=" + PAIds + "&commaseparated_attrid=" + commaseparated_attrid + "&forcetocart=" + forcetocart,
dataType: "json",
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function (result) {
$(".loader").removeClass("show");
$(".loader").addClass("hide");
if (result.status == 1) {
loadMiniCart();
prtotal = $(".carttotalprice").html();
// $("#calculate_shipping_charge").trigger("click");
// updateshippingCharge();
var shipping_charge = 0;
var charge_symbol = 0;
if ($(".show_shipping_charge").length) {
shipping_charge = $(
"input:radio.show_shipping_charge:checked"
).attr("data-charge");
charge_symbol = $("input:radio.show_shipping_charge:checked").attr(
"data-charge-symbol"
);
}
var grandtotal = $(".shpsubtotal").attr("data-subtotal");
grandtotal = parseFloat(shipping_charge) + parseFloat(grandtotal);
grandtotal = grandtotal.toFixed(2);
$(".shpsubtotal").html(prtotal);
$("#shipping_charge").html(charge_symbol);
$(".shpgrdtotal").html(symbol + grandtotal);
newprice = parseInt(prdqty) * parseFloat(prdprice);
$(this).attr("data-price", newprice);
$.ajax({
url: site_url1 + "/product/reformatCurrency",
type: "post",
data: "prdprc=" + newprice,
success: function (result) {
if (result) {
$(".prod_price" + prodattribute).html(result);
$(".prod_price" + prodattribute).attr("data-price", result);
} else {
$(".prod_price" + prodattribute).html(newprice.toFixed(2));
$(".prod_price" + prodattribute).attr(
"data-price",
newprice.toFixed(2)
);
}
/*$(".c-layout-page").css({
"margin-top": $(".c-layout-header").height() + "px",
});*/
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
//$("#calculate_shipping_charge").trigger("click");
//updateshippingCharge();
/*if (res[2] != '' && wbGoogleAnalyticId != '' && wbStandardTracking == 1 && wbEcommerceTracking == 1) {
var gtaData = JSON.parse(res[2]);
gtag('event', 'add_to_cart', { "event_label": gtaData.name, "items": res[2] });
}*/
swal(
{
title: front_shopping_cart_label,
text: front_shopping_cart_updated_msg,
type: "success",
},
function () {
loadShopppingCart();
/*$(".c-layout-page").css({
"margin-top": $(".c-layout-header").height() + "px",
});*/
}
);
//swal("Shopping Cart!", "Shopping Cart updated successfully", "success");
//window.location.href = site_url;
} else if(result.status == 2) {
swal(
{
title: front_shopping_cart_label,
text: result.message,
type: "warning",
showCancelButton: true,
confirmButtonText: "Continue",
cancelButtonText: "Cancel",
},
function(isConfirm) {
if (isConfirm) {
$('.addtocart[data-name=' + prdid + ']').attr("data-forcetocart","Y");
$('.addtocart[data-name=' + prdid + ']').trigger('click');
}
}
);
}else if(result.status == 3) {
swal(
{
title: front_shopping_cart_label,
text: result.message,
type: "warning",
},
function () {
}
);
}else {
swal(
{
title: front_shopping_cart_label,
text: front_shopping_cart_updated_error,
type: "info",
},
function () {
loadShopppingCart();
/*$(".c-layout-page").css({
"margin-top": $(".c-layout-header").height() + "px",
});*/
}
);
}
/*var res = "";
if (result) {
res = result.split("||");
}
if (res[1] != "") {
$(".modshopcartbox").html(res[1]);
}*/
/*if (res[0] > 0) {
$(".totalcart").html(res[0]);
prtotal = $(".carttotalprice").html();
$("#calculate_shipping_charge").trigger("click");
updateshippingCharge();
var shipping_charge = 0;
var charge_symbol = 0;
if ($('.show_shipping_charge').length) {
shipping_charge = $("input:radio.show_shipping_charge:checked").attr('data-charge');
charge_symbol = $("input:radio.show_shipping_charge:checked").attr('data-charge-symbol');
}
var grandtotal = $(".shpsubtotal").attr('data-subtotal');
grandtotal = parseFloat(shipping_charge) + parseFloat(grandtotal);
grandtotal = grandtotal.toFixed(2);
$(".shpsubtotal").html(prtotal);
$("#shipping_charge").html(charge_symbol);
$(".shpgrdtotal").html(symbol + grandtotal);
newprice = parseInt(prdqty) * parseFloat(prdprice);
$(this).attr("data-price", newprice);
$.ajax({
url: site_url1 + '/product/reformatCurrency',
type: 'post',
data: 'prdprc=' + newprice,
success: function(result) {
if (result) {
$(".prod_price" + prodattribute).html(result);
$(".prod_price" + prodattribute).attr("data-price", result);
} else {
$(".prod_price" + prodattribute).html(newprice.toFixed(2));
$(".prod_price" + prodattribute).attr("data-price", newprice.toFixed(2));
}
},
error: function(jqXHR, textStatus, errorThrown) {
return false;
}
});
$("#calculate_shipping_charge").trigger("click");
updateshippingCharge();
if (res[2] != '' && wbGoogleAnalyticId != '' && wbStandardTracking == 1 && wbEcommerceTracking == 1) {
var gtaData = JSON.parse(res[2]);
gtag('event', 'add_to_cart', { "event_label": gtaData.name, "items": res[2] });
}
swal("Shopping Cart!", "Shopping Cart updated successfully", "success");
//window.location.href = site_url;
loadShopppingCart();
} else {
swal("Shopping Cart!", "There is some issue in Shopping Cart", "info");
//window.location.href = site_url;
loadShopppingCart();
}*/
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
}
});
$("body").delegate(".prdqty", "keyup", function (e) {
e.preventDefault();
e.stopImmediatePropagation();
var custid = "";
var prdid = "";
var prdqty = 1;
var prtotal = 0;
var prdprice = 0;
var newprice = 0;
custid = $("#hdn_custid").val();
index = $(this).attr("data-index");
prdqty = $(this).val();
prdid = $(this).attr("data-name");
prdprice = $(this).attr("data-price");
var PAIds = $(this).attr("data-paids");
var commaseparated_attrid = $(this).attr("data-attribute");
var prodattribute = $(this).attr("data-prodattribute");
if (commaseparated_attrid == undefined) {
commaseparated_attrid = "";
}
$(".delcartitem[data-prodattribute='" + prodattribute + "']").attr(
"data-qty",
prdqty
);
if (prdqty == undefined || prdqty == 0) {
prdqty = 1;
$(".c-item-" + index).val(prdqty);
return false;
}
var site_url1 = getBaseUrl();
if (prdid != "" && prdqty > 0) {
var forcetocart = '';
if (typeof $(".addtocart").data('forcetocart') !== 'undefined') {
forcetocart = $(this).attr("data-forcetocart");
}
$(this).val(prdqty);
$.ajax({
url: site_url1 + "/shoppingcart/addtocart",
type: "post",
cache: false,
data: "prdname=" + prdid + "&custid=" + custid + "&prdqty=" + prdqty + "&pn=sh" + "&PAIds=" + PAIds + "&commaseparated_attrid=" + commaseparated_attrid + "&forcetocart=" + forcetocart,
dataType: "json",
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function (result) {
$(".loader").removeClass("show");
$(".loader").addClass("hide");
if (result.status == 1) {
loadMiniCart();
prtotal = $(".carttotalprice").html();
var shipping_charge = 0;
var charge_symbol = 0;
if ($(".show_shipping_charge").length) {
shipping_charge = $(
"input:radio.show_shipping_charge:checked"
).attr("data-charge");
charge_symbol = $("input:radio.show_shipping_charge:checked").attr(
"data-charge-symbol"
);
}
var grandtotal = $(".shpsubtotal").attr("data-subtotal");
grandtotal = parseFloat(shipping_charge) + parseFloat(grandtotal);
grandtotal = grandtotal.toFixed(2);
$(".shpsubtotal").html(prtotal);
$("#shipping_charge").html(charge_symbol);
$(".shpgrdtotal").html(symbol + grandtotal);
newprice = parseInt(prdqty) * parseFloat(prdprice);
$(this).attr("data-price", newprice);
$.ajax({
url: site_url1 + "/product/reformatCurrency",
type: "post",
data: "prdprc=" + newprice,
success: function (result) {
if (result) {
$(".prod_price" + prodattribute).html(result);
} else {
$(".prod_price" + prodattribute).html(newprice.toFixed(2));
}
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
swal(
front_shopping_cart_label,
front_shopping_cart_updated_msg,
"success"
);
//window.location.href = site_url;
loadShopppingCart();
} else if(result.status == 2) {
swal(
{
title: front_shopping_cart_label,
text: result.message,
type: "warning",
showCancelButton: true,
confirmButtonText: "Continue",
cancelButtonText: "Cancel",
},
function(isConfirm) {
if (isConfirm) {
$('.addtocart[data-name=' + prdid + ']').attr("data-forcetocart","Y");
$('.addtocart[data-name=' + prdid + ']').trigger('click');
}
}
);
}else if(result.status == 3) {
swal(
{
title: front_shopping_cart_label,
text: result.message,
type: "warning",
},
function () {
}
);
}else {
swal(
"Shopping Cart!",
"There is some issue in Shopping Cart",
"info"
);
//window.location.href = site_url;
loadShopppingCart();
}
/*var res = "";
if (result) {
res = result.split("||");
}
if (res[1] != "") {
$(".modshopcartbox").html(res[1]);
}
if (res[0] > 0) {
$(".totalcart").html(res[0]);
prtotal = $(".carttotalprice").html();
var shipping_charge = 0;
var charge_symbol = 0;
if ($('.show_shipping_charge').length) {
shipping_charge = $("input:radio.show_shipping_charge:checked").attr('data-charge');
charge_symbol = $("input:radio.show_shipping_charge:checked").attr('data-charge-symbol');
}
var grandtotal = $(".shpsubtotal").attr('data-subtotal');
grandtotal = parseFloat(shipping_charge) + parseFloat(grandtotal);
grandtotal = grandtotal.toFixed(2);
$(".shpsubtotal").html(prtotal);
$("#shipping_charge").html(charge_symbol);
$(".shpgrdtotal").html(symbol + grandtotal);
newprice = parseInt(prdqty) * parseFloat(prdprice);
$(this).attr("data-price", newprice);
$.ajax({
url: site_url1 + '/product/reformatCurrency',
type: 'post',
data: 'prdprc=' + newprice,
success: function(result) {
if (result) {
$(".prod_price" + prodattribute).html(result);
} else {
$(".prod_price" + prodattribute).html(newprice.toFixed(2));
}
},
error: function(jqXHR, textStatus, errorThrown) {
return false;
}
});
swal("Shopping Cart!", "Shopping Cart updated successfully", "success");
//window.location.href = site_url;
loadShopppingCart();
} else {
swal("Shopping Cart!", "There is some issue in Shopping Cart", "info");
//window.location.href = site_url;
loadShopppingCart();
}*/
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
}
});
$("body").delegate(".removewishlist", "click", function (e) {
e.preventDefault();
e.stopImmediatePropagation();
var wishlist = $(this).attr("data-name");
var site_url1 = getBaseUrl();
if (wishlist != "") {
swal(
{
title: front_wishlist_remove_confirm_msg,
type: "warning",
showCancelButton: true,
confirmButtonText: front_wishlist_remove_yes,
cancelButtonText: front_wishlist_remove_no,
},
function () {
$.ajax({
url: site_url1 + "/product/removefromwishlist",
type: "post",
data: "wishlist=" + wishlist,
success: function (result) {
if (result >= 0) {
window.location.reload(true);
} else {
swal("Wishlist!", front_wishlist_issue, "info");
}
return false;
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
}
);
}
return false;
});
// function updatewarrantyCharge() {
$("body").delegate(".warrantyproc", "click", function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var baseUrl = getBaseUrl();
var warranty_price = $(this).attr("data-warranty-price");
var page = $(this).attr("data-page");
var form_ship_data =
"&ship_first_name=" +
$("#shipping_firstName").val() +
"&ship_middle_name=" +
$("#shipping_middleName").val() +
"&ship_last_name=" +
$("#shipping_lastName").val() +
"&ship_company_name=" +
$("#shipping_companyName").val() +
"&ship_address1=" +
$("#form_shipping_address1").val() +
"&ship_address2=" +
$("#form_shipping_address2").val() +
"&ship_email=" +
$("#shipping_emailid").val() +
"&ship_phone=" +
$("#shipping_contact").val() +
"&ship_fax=" +
$("#shipping_fax").val();
var form_bil_data =
"&bil_first_name=" +
$("#billing_firstName").val() +
"&bil_middle_name=" +
$("#billing_middleName").val() +
"&bil_last_name=" +
$("#billing_lastName").val() +
"&bil_company_name=" +
$("#billing_companyName").val() +
"&bil_address1=" +
$("#form_billing_address1").val() +
"&bil_address2=" +
$("#form_billing_address2").val() +
"&bil_email=" +
$("#billing_emailid").val() +
"&bil_phone=" +
$("#billing_contact").val() +
"&bil_fax=" +
$("#billing_fax").val();
var bill_diff_address = 0;
if ($("#chkbilladdress").prop("checked") == true || $('#selected_shipping_method_slug').val() == 'instorepickup') {
bill_diff_address = 1;
}
var other_data = "&bill_diff_address=" + bill_diff_address + '&shipping_method_slug=' + $('#selected_shipping_method_slug').val() + '&preferred_range_from=' + $('#rangeFrom').val() + '&preferred_range_to=' + $('#rangeTo').val() + '&sales_person=' + $('#form_salesPerson').val();
if (warranty_price != "") {
swal({
title: front_warranty_add_confrm_msg,
type: "warning",
showCancelButton: true,
confirmButtonText: front_warranty_add_yes,
cancelButtonText: front_warranty_add_no,
closeOnConfirm: false,
closeOnCancel: true,
},function () {
$.ajax({
type: "POST",
cache: true,
url: baseUrl + "/shoppingcart/cartupdatewarrantydata/update",
data: form_ship_data + form_bil_data + other_data,
success: function (response) {
swal({
title: front_success,
text: front_warranty_add_success,
type: "success",
},
function () {
if (page == "checkout") {
location.reload();
} else {
loadShopppingCart();
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
return false;
},
});
return false;
});
/*$.ajax({
type: "POST",
cache: true,
url: baseUrl + "/shoppingcart/cartupdatewarrantydata/update",
data: form_ship_data + form_bil_data + other_data,
success: function(result) {
if (page == "checkout") {
location.reload();
} else {
loadShopppingCart();
}
return true;
},
error: function(jqXHR, textStatus, errorThrown) {
return false;
},
});*/
}
});
$("body").delegate("#delwarranty,.warrantyunproc", "click", function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var baseUrl = getBaseUrl();
var page = $(this).attr("data-page");
var form_ship_data =
"&ship_first_name=" +
$("#shipping_firstName").val() +
"&ship_middle_name=" +
$("#shipping_middleName").val() +
"&ship_last_name=" +
$("#shipping_lastName").val() +
"&ship_company_name=" +
$("#shipping_companyName").val() +
"&ship_address1=" +
$("#form_shipping_address1").val() +
"&ship_address2=" +
$("#form_shipping_address2").val() +
"&ship_email=" +
$("#shipping_emailid").val() +
"&ship_phone=" +
$("#shipping_contact").val() +
"&ship_fax=" +
$("#shipping_fax").val();
var form_bil_data =
"&bil_first_name=" +
$("#billing_firstName").val() +
"&bil_middle_name=" +
$("#billing_middleName").val() +
"&bil_last_name=" +
$("#billing_lastName").val() +
"&bil_company_name=" +
$("#billing_companyName").val() +
"&bil_address1=" +
$("#form_billing_address1").val() +
"&bil_address2=" +
$("#form_billing_address2").val() +
"&bil_email=" +
$("#billing_emailid").val() +
"&bil_phone=" +
$("#billing_contact").val() +
"&bil_fax=" +
$("#billing_fax").val();
var bill_diff_address = 0;
if ($("#chkbilladdress").prop("checked") == true || $('#selected_shipping_method_slug').val() == 'instorepickup') {
bill_diff_address = 1;
}
var other_data = "&bill_diff_address=" + bill_diff_address + '&shipping_method_slug=' + $('#selected_shipping_method_slug').val() + '&preferred_range_from=' + $('#rangeFrom').val() + '&preferred_range_to=' + $('#rangeTo').val() + '&sales_person=' + $('#form_salesPerson').val();
swal({
title: front_warranty_remove_confrm_msg,
type: "warning",
showCancelButton: true,
confirmButtonText: front_warranty_remove_yes,
cancelButtonText: front_warranty_remove_no,
closeOnConfirm: false,
closeOnCancel: true,
},
function() {
$.ajax({
type: "POST",
cache: false,
url: baseUrl + "/shoppingcart/cartupdatewarrantydata/remove",
data: form_ship_data + form_bil_data + other_data,
success: function(response) {
swal({
title: front_success,
text: front_warranty_remove_successfully,
type: "success",
},
function() {
if (page == "checkout") {
window.location.reload();
} else {
loadShopppingCart();
}
}
);
},
});
return false;
}
);
});
//}
$("body").delegate(".applycoupon", "click", function() {
var copcode = $("#coupon_code").val();
var baseUrl = getBaseUrl();
var remove_cp_id = '';
if (copcode != "" && copcode != null) {
$.ajax({
type: "POST",
cache: true,
url: baseUrl + "/applycouponcode",
data: "copcode=" + copcode,
success: function(result) {
var jsonres = $.parseJSON(result);
console.log("jsonresonse" + jsonres);
if (jsonres.responce_code == 1) {
swal(
front_congratulations_lbl,
front_coupon_applied_success_msg,
"success"
);
$("#coupon_code").val("");
/*$(".c-layout-page").css({
"margin-top": $(".c-layout-header").height() + "px",
});*/
loadShopppingCart();
//window.location.reload(true);
} else if(jsonres.responce_code == 2)
{
swal(
front_congratulations_lbl,
front_coupon_applied_warning_msg,
"warning"
);
$("#coupon_code").val("");
loadShopppingCart();
}
else {
if (jsonres.applied_coupon_id != '' && jsonres.applied_coupon_id != undefined) {
var remove_cp_id = jsonres.applied_coupon_id;
swal({
title: jsonres.message,
type: "warning",
showCancelButton: true,
confirmButtonText: jsonres.front_warranty_remove_yes,
cancelButtonText: jsonres.front_warranty_remove_no,
},
function() {
var url = "applycouponcode";
$.ajax({
type: "POST",
url: baseUrl + "/" + url,
cache: false,
data: "remove_cp_id=" + remove_cp_id,
success: function(response) {
if (response == 1) {
$('.applycoupon').trigger('click');
}
},
});
return false;
}
);
} else {
swal(front_error_lbl, jsonres.message, "error");
$("#coupon_code").val("");
}
}
return false;
},
error: function(jqXHR, textStatus, errorThrown) {
return false;
},
});
}
});
$("body").delegate(".delcouponitem", "click", function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var couponid = $(this).attr("data-id");
var baseUrl = getBaseUrl();
if (couponid != "") {
swal({
title: front_coupon_delete_confirm_msg,
type: "warning",
showCancelButton: true,
confirmButtonText: front_warranty_remove_yes,
cancelButtonText: front_warranty_remove_no,
},
function() {
var url = "removecouponcode";
$.ajax({
type: "POST",
url: baseUrl + "/" + url,
cache: false,
data: "cpnid=" + couponid,
success: function(response) {
if (response) {
setTimeout(
function() {
swal(front_success, front_coupon_delete_success_msg, "success");
$(".c-layout-page").css({ "margin-top": $(".c-layout-header").data('scroll') + "px" });
loadShopppingCart();
}, 700);
//window.location.reload(true);
/*$(".c-layout-page").css({
"margin-top": $(".c-layout-header").height() + "px",
});*/
loadShopppingCart();
}
},
});
return false;
}
);
}
return false;
});
if (typeof productType != "undefined" && productType == 1) {
/* $(document).on('change', '.product_attribute_group_selectbox', function () {
var sale_price = 0;
var variasion = 0;
sale_price = $("#hdn_sale_price").val();
var commaseparated_attribute_id = '';
$.each($(".product_attribute_group_selectbox"), function () {
if ($(this).val() != '') {
var attribute_price_variation = $("option:selected", this).attr('attribute-price-variation');
if (attribute_price_variation == '') {
attribute_price_variation = 0;
}
variasion = parseFloat(variasion) + parseFloat(attribute_price_variation);
commaseparated_attribute_id = commaseparated_attribute_id + $(this).val() + ',';
}
});
$.each($(".product_attribute_group_radio input[type='radio']:checked"), function () {
var attribute_price_variation1 = $(this).attr('attribute-price-variation');
if (attribute_price_variation1 == '') {
attribute_price_variation1 = 0;
}
console.log(variasion);
console.log(parseFloat(attribute_price_variation1));
variasion = variasion + parseFloat(attribute_price_variation1);
commaseparated_attribute_id = commaseparated_attribute_id + $(this).val() + ',';
});
var new_sale_price = parseFloat(sale_price) + parseFloat(variasion);
var site_url = getBaseUrl();
if (commaseparated_attribute_id != '') {
commaseparated_attribute_id = commaseparated_attribute_id.slice(0, -1);
}
// var currentAttributesGroupId = '';
// var currentAttributesGroupId = $this.attributes['attribute-group'].value;
// var prevAttributeGroup = $('#selected_attribute_group').val();
// if (prevAttributeGroup == '') {
// $('#selected_attribute_group').val(currentAttributesGroupId);
// }
// var selectedAttributesGroupId = $('#selected_attribute_group').val();
$("#commaseparated_attribute_id").val(commaseparated_attribute_id);
var productId = $('#prdDataId').val();
$.ajax({
type: "POST",
dataType: "json",
url: site_url + "/product/getproductprice",
cache: false,
data: "sale_price=" + new_sale_price + '&commaseparated_attribute_id=' + commaseparated_attribute_id + '&product_id=' + productId,
success: function (response) {
if (response['sale_price'] != '') {
$("#sale_price_id").html(response['sale_price']);
$("#msrp_price_id").html(response['msrp_price']);
}
}
});
});
*/
}
function changeSimpleAttribute($this) {
var sale_price = 0;
var variasion = 0;
sale_price = $("#hdn_sale_price").val();
var commaseparated_attribute_id = "";
$.each($(".product_attribute_group_selectbox"), function () {
if ($(this).val() != "") {
var attribute_price_variation = $("option:selected", this).attr(
"attribute-price-variation"
);
if (attribute_price_variation == "") {
attribute_price_variation = 0;
}
variasion = parseFloat(variasion) + parseFloat(attribute_price_variation);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
}
});
$.each(
$(".product_attribute_group_radio input[type='radio']:checked"),
function () {
var attribute_price_variation1 = $(this).attr(
"attribute-price-variation"
);
if (attribute_price_variation1 == "") {
attribute_price_variation1 = 0;
}
variasion = variasion + parseFloat(attribute_price_variation1);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
}
);
var new_sale_price = parseFloat(sale_price) + parseFloat(variasion);
var site_url = getBaseUrl();
if (commaseparated_attribute_id != "") {
commaseparated_attribute_id = commaseparated_attribute_id.slice(0, -1);
}
// var currentAttributesGroupId = '';
// var currentAttributesGroupId = $this.attributes['attribute-group'].value;
// var prevAttributeGroup = $('#selected_attribute_group').val();
// if (prevAttributeGroup == '') {
// $('#selected_attribute_group').val(currentAttributesGroupId);
// }
// var selectedAttributesGroupId = $('#selected_attribute_group').val();
$("#commaseparated_attribute_id").val(commaseparated_attribute_id);
var productId = $("#prdDataId").val();
$.ajax({
type: "POST",
dataType: "json",
url: site_url + "/product/getproductprice",
cache: false,
data:
"sale_price=" +
new_sale_price +
"&commaseparated_attribute_id=" +
commaseparated_attribute_id +
"&product_id=" +
productId,
success: function (response) {
if (response["sale_price"] != "") {
$("#sale_price_id").html(response["sale_price"]);
$("#msrp_price_id").html(response["msrp_price"]);
}
},
});
}
var aGSequence = [];
var attributeGroupSequence = "";
var aAttribute = [];
var availableAttribute = "";
function getproductvariationdata($this) {
var variasion = 0;
var commaseparated_attribute_id = "";
var attributeGroupVisible = {};
var selectedAttributesId = [];
var currentAttributesGroupId = "";
// var attributeGroup = [];
// var attributeSelect = '';
// var radioButtons = $(".gray-box");
// radioButtons.each(function () {
// var selectedOption = $(this).find("select option:selected").attr('attribute-group');
// if($.inArray(selectedOption,attributeGroup) == -1 && selectedOption != undefined)
// {
// attributeGroup.push(parseInt(selectedOption));
// }
// var radioOption = $(this).find("input[type='radio']").attr('attribute-group');
// if($.inArray(radioOption,attributeGroup) == -1 && radioOption != undefined)
// {
// attributeGroup.push(parseInt(radioOption ));
// }
// });
var gray_box_count = $("#product-variation .gray-box").length;
// if(typeof $this.attributes["attribute-group"] !== "undefined")
// {
var currentAttributesGroupId = $this.attributes["attribute-group"].value;
// }
// else
// {
// $("#product-variation .addtocart").attr("disabled", true);
// $("#sale_price_id").text($("#first_sale_price").val());
// return false;
// }
attributeSelect = currentAttributesGroupId;
if (jQuery.inArray(currentAttributesGroupId, aGSequence) == -1) {
aGSequence.push(currentAttributesGroupId);
}
var attributeGroupSequence = aGSequence.join(",");
$.each(
$("option[attribute-group*='" + currentAttributesGroupId + "']"),
function () {
if (
$(this).val() != "" &&
$(this).hasClass("selected_attribute") == true
) {
if (jQuery.inArray($(this).attr("attribute-id"), aAttribute) == -1) {
aAttribute.push($(this).attr("attribute-id"));
}
}
}
);
$.each(
$("input[attribute-group*='" + currentAttributesGroupId + "']"),
function () {
if (
$(this).val() != "" &&
$(this).closest("li").hasClass("selected_attribute") == true
) {
if (jQuery.inArray($(this).attr("attribute-id"), aAttribute) == -1) {
aAttribute.push($(this).attr("attribute-id"));
}
}
}
);
jQuery.each(aGSequence, function (i, val) {
var attrIndex = aGSequence.indexOf(currentAttributesGroupId);
if (attrIndex < i) {
$.each($("option[attribute-group*='" + val + "']"), function () {
$(this).removeAttr("selected");
var $this1 = $(this);
aAttribute = jQuery.grep(aAttribute, function (value) {
return value != $this1.attr("attribute-id");
});
});
$.each($("input[attribute-group*='" + val + "']"), function () {
$(this).removeAttr("checked");
var $this1 = $(this);
aAttribute = jQuery.grep(aAttribute, function (value) {
return value != $this1.attr("attribute-id");
});
});
}
});
availableAttribute = aAttribute.join(",");
var prevAttribute = $("#selected_attribute").val();
var currAttribute =
prevAttribute + $this.attributes["attribute-id"].value + ",";
$("#selected_attribute").val(currAttribute);
if (aGSequence[0] == currentAttributesGroupId) {
$.each(
$("option:selected[attribute-group*='" + currentAttributesGroupId + "']"),
function () {
if (
$(this).val() != "" &&
$(this).hasClass("selected_attribute") == true
) {
var attribute_price_variation = $(this).attr(
"attribute-price-variation"
);
if (attribute_price_variation == "") {
attribute_price_variation = 0;
}
variasion =
parseFloat(variasion) + parseFloat(attribute_price_variation);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[$(this).attr("attribute-group")] = $(this).attr(
"attribute-name"
);
var attribute_id = $(this).attr("attribute-id");
// if($.inArray(attribute_id,selectedAttributesId) == -1)
// {
selectedAttributesId.push(attribute_id);
// }
}
}
);
$.each(
$(
"input[type='radio']:checked[attribute-group*='" +
currentAttributesGroupId +
"']"
),
function () {
if (
$(this).val() != "" &&
$(this).closest("li").hasClass("selected_attribute") == true
) {
var attribute_price_variation1 = $(this).attr(
"attribute-price-variation"
);
if (attribute_price_variation1 == "") {
attribute_price_variation1 = 0;
}
variasion = variasion + parseFloat(attribute_price_variation1);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[$(this).attr("attribute-group")] = $(this).attr(
"attribute-name"
);
var attribute_id = $(this).attr("attribute-id");
// if($.inArray(attribute_id,selectedAttributesId) == -1)
// {
selectedAttributesId.push(attribute_id);
// }
}
}
);
} else {
$.each($(".product_attribute_group_selectbox"), function () {
if (
$(this).val() != "" &&
$("option:selected", this).hasClass("selected_attribute") == true
) {
var attribute_price_variation = $("option:selected", this).attr(
"attribute-price-variation"
);
if (attribute_price_variation == "") {
attribute_price_variation = 0;
}
variasion =
parseFloat(variasion) + parseFloat(attribute_price_variation);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[
$("option:selected", this).attr("attribute-group")
] = $("option:selected", this).attr("attribute-name");
var attribute_id = $("option:selected", this).attr("attribute-id");
// if($.inArray(attribute_id,selectedAttributesId) == -1)
// {
selectedAttributesId.push(attribute_id);
// }
}
});
$.each(
$(".product_attribute_group_radio input[type='radio']:checked"),
function () {
if ($(this).closest("li").hasClass("selected_attribute") == true) {
var attribute_price_variation1 = $(this).attr(
"attribute-price-variation"
);
if (attribute_price_variation1 == "") {
attribute_price_variation1 = 0;
}
variasion = variasion + parseFloat(attribute_price_variation1);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[$(this).attr("attribute-group")] = $(this).attr(
"attribute-name"
);
var attribute_id = $(this).attr("attribute-id");
// if($.inArray(attribute_id,selectedAttributesId) == -1)
// {
selectedAttributesId.push(attribute_id);
// }
}
}
);
}
if (commaseparated_attribute_id != "") {
commaseparated_attribute_id = commaseparated_attribute_id.slice(0, -1);
}
currAttribute = currAttribute.replace(/,\s*$/, "");
currAttribute = currAttribute.split(",");
var selAttrIds = [];
jQuery.grep(currAttribute, function (el) {
if (jQuery.inArray(el, selectedAttributesId) != -1) {
selAttrIds.push(el);
}
});
// console.log(attributeSelect, attributeGroup);
// var firstSalePrice = $("#first_sale_price").val();
// var currentSalePrice = $("#sale_price_id").text();
// if(firstSalePrice == currentSalePrice)
// {
// $.each(attributeGroup , function(index, val) {
// if(val > attributeSelect)
// {
// var radiobtnLast = $(".gray-box input[attribute-group='"+val+"']").last();
// if(radiobtnLast.attr('attribute-name') == "None"){
// radiobtnLast.prop( "checked", true );
// }
// else{
// $(".gray-box input[attribute-group='"+val+"']").first().prop( "checked", true );
// }
// }
// });
// }
// var variasion = 0;
// var selectedAttributesId = [];
// var commaseparated_attribute_id = [];
// var radioButtons = $(".gray-box input[type='radio']");
// radioButtons.each(function () {
// if ($(this).prop("checked")) {
// if($.inArray($(this).attr('attribute-id'),selectedAttributesId) == -1)
// {
// selectedAttributesId.push($(this).attr('attribute-id'));
// commaseparated_attribute_id.push($(this).val());
// variasion = parseFloat(variasion) + parseFloat($(this).attr("attribute-price-variation"));
// }
// }
// });
// var selectBox = $(".gray-box select");
// selectBox.each(function () {
// var selectedOption = $(this).find("option:selected").attr('attribute-id');
// if($.inArray(selectedOption,selectedAttributesId) == -1)
// {
// selectedAttributesId.push(selectedOption);
// commaseparated_attribute_id.push($(this).val());
// variasion = parseFloat(variasion) + parseFloat($(this).find("option:selected").attr("attribute-price-variation"));
// }
// });
// commaseparated_attribute_id = commaseparated_attribute_id.join(",");
// var selectedAttributesId = selectedAttributesId.join(",");
var selectedAttributesId = selAttrIds.join(",");
$("#commaseparated_attribute_id").val(commaseparated_attribute_id);
if ($("#prdDataId").length > 0) {
var productId = $("#prdDataId").val();
} else {
var productId = $(".product_id").val(); //add by REN02
}
var site_url = getBaseUrl();
var selected_commaseparated_attribute;
if (commaseparated_attribute_id != "") {
$.ajax({
type: "POST",
dataType: "json",
url: site_url + "/product/getvariationattribute",
cache: false,
data:
"commaseparated_attribute_id=" +
commaseparated_attribute_id +
"&product_id=" +
productId +
"&variasion=" +
variasion +
"&selectedAttributesId=" +
selectedAttributesId +
"&attributeGroupSequence=" +
attributeGroupSequence +
"&availableAttribute=" +
availableAttribute,
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function (response) {
$("#product-variation-attribute").html(response.html);
$("#collection_frame").removeClass("hide");
$("#collection_frame").addClass("show");
$("#downloadImage").attr("href", response.imageFileName);
$(".attribute-variation").html(response.attributesCombination);
$(".attribute-variation-list").html(response.attributesCombinationList);
$("#product_variation_gallery").html(response["rawitemGalleryHtml"]);
if (response["rawitemGalleryHtml"] != "") {
// $(".pgwSlideshow").pgwSlideshow({
// autoSlide: false,
// displayList: true,
// displayControls: false,
// touchControls: false,
// });
// $(".ps-current ul li").zoom();
}
$("#product_variation_dimension_message").hide();
$("#product_variation_dimension").html(
response["rawitemDimensionHtml"]
);
$("#product_variation_weight").html(response["weight"]);
var selected_commaseparated_attribute = commaseparated_attribute_id.split(
","
).length;
if (selected_commaseparated_attribute == gray_box_count) {
if ($(".gray-box .last").hasClass("disable_attribute")) {
$(".gray-box .last")
.removeClass("disable_attribute")
.addClass("selected_attribute");
$(".gray-box .last")
.siblings()
.removeClass("selected_attribute")
.addClass("disable_attribute");
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("li.selected_attribute:first")
.find("input")
.prop("checked", true);
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("select")
.find("option.selected_attribute:first")
.prop("selected", true);
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("li.selected_attribute:first")
.find("input")
.trigger("click");
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("select")
.find("option.selected_attribute:first")
.prop("selected", true)
.trigger("change");
}
}
getProductVariationData(
commaseparated_attribute_id,
gray_box_count,
selectedAttributesId,
productId,
variasion,
attributeGroupVisible
);
$(".loader").removeClass("show");
$(".loader").addClass("hide");
},
});
}
}
function getproductvariationdataBkp($this) {
var gray_box_count = $("#product-variation .gray-box").length;
var variasion = 0;
var commaseparated_attribute_id = "";
var attributeGroupVisible = {};
var selectedAttributesId = [];
var currentAttributesGroupId = "";
var currentAttributesGroupId = $this.attributes["attribute-group"].value;
if (jQuery.inArray(currentAttributesGroupId, aGSequence) == -1) {
aGSequence.push(currentAttributesGroupId);
}
var attributeGroupSequence = aGSequence.join(",");
if (aGSequence[0] == currentAttributesGroupId) {
aAttribute = [];
}
$.each(
$("option[attribute-group*='" + currentAttributesGroupId + "']"),
function () {
if (
$(this).val() != "" &&
$(this).hasClass("selected_attribute") == true
) {
if (jQuery.inArray($(this).attr("attribute-id"), aAttribute) == -1) {
aAttribute.push($(this).attr("attribute-id"));
}
}
}
);
$.each(
$("input[attribute-group*='" + currentAttributesGroupId + "']"),
function () {
if (
$(this).val() != "" &&
$(this).closest("li").hasClass("selected_attribute") == true
) {
if (jQuery.inArray($(this).attr("attribute-id"), aAttribute) == -1) {
aAttribute.push($(this).attr("attribute-id"));
}
}
}
);
availableAttribute = aAttribute.join(",");
var prevAttribute = $("#selected_attribute").val();
var currAttribute =
prevAttribute + $this.attributes["attribute-id"].value + ",";
$("#selected_attribute").val(currAttribute);
if (aGSequence[0] == currentAttributesGroupId) {
$.each(
$("option:selected[attribute-group*='" + currentAttributesGroupId + "']"),
function () {
if (
$(this).val() != "" &&
$(this).hasClass("selected_attribute") == true
) {
var attribute_price_variation = $(this).attr(
"attribute-price-variation"
);
if (attribute_price_variation == "") {
attribute_price_variation = 0;
}
variasion =
parseFloat(variasion) + parseFloat(attribute_price_variation);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[$(this).attr("attribute-group")] = $(this).attr(
"attribute-name"
);
var attribute_id = $(this).attr("attribute-id");
selectedAttributesId.push(attribute_id);
}
}
);
$.each(
$(
"input[type='radio']:checked[attribute-group*='" +
currentAttributesGroupId +
"']"
),
function () {
if (
$(this).val() != "" &&
$(this).closest("li").hasClass("selected_attribute") == true
) {
var attribute_price_variation1 = $(this).attr(
"attribute-price-variation"
);
if (attribute_price_variation1 == "") {
attribute_price_variation1 = 0;
}
variasion = variasion + parseFloat(attribute_price_variation1);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[$(this).attr("attribute-group")] = $(this).attr(
"attribute-name"
);
var attribute_id = $(this).attr("attribute-id");
selectedAttributesId.push(attribute_id);
}
}
);
} else {
$.each($(".product_attribute_group_selectbox"), function () {
if (
$(this).val() != "" &&
$("option:selected", this).hasClass("selected_attribute") == true
) {
var attribute_price_variation = $("option:selected", this).attr(
"attribute-price-variation"
);
if (attribute_price_variation == "") {
attribute_price_variation = 0;
}
variasion =
parseFloat(variasion) + parseFloat(attribute_price_variation);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[
$("option:selected", this).attr("attribute-group")
] = $("option:selected", this).attr("attribute-name");
var attribute_id = $("option:selected", this).attr("attribute-id");
selectedAttributesId.push(attribute_id);
}
});
$.each(
$(".product_attribute_group_radio input[type='radio']:checked"),
function () {
if ($(this).closest("li").hasClass("selected_attribute") == true) {
var attribute_price_variation1 = $(this).attr(
"attribute-price-variation"
);
if (attribute_price_variation1 == "") {
attribute_price_variation1 = 0;
}
variasion = variasion + parseFloat(attribute_price_variation1);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
attributeGroupVisible[$(this).attr("attribute-group")] = $(this).attr(
"attribute-name"
);
var attribute_id = $(this).attr("attribute-id");
selectedAttributesId.push(attribute_id);
}
}
);
}
if (commaseparated_attribute_id != "") {
commaseparated_attribute_id = commaseparated_attribute_id.slice(0, -1);
}
currAttribute = currAttribute.replace(/,\s*$/, "");
currAttribute = currAttribute.split(",");
var selAttrIds = [];
jQuery.grep(currAttribute, function (el) {
if (jQuery.inArray(el, selectedAttributesId) != -1) {
selAttrIds.push(el);
}
});
var selectedAttributesId = selAttrIds.join(",");
$("#commaseparated_attribute_id").val(commaseparated_attribute_id);
var productId = $("#prdDataId").val();
var site_url = getBaseUrl();
var selected_commaseparated_attribute;
if (commaseparated_attribute_id != "") {
$.ajax({
type: "POST",
dataType: "json",
url: site_url + "/product/getvariationattribute",
cache: false,
data:
"commaseparated_attribute_id=" +
commaseparated_attribute_id +
"&product_id=" +
productId +
"&variasion=" +
variasion +
"&selectedAttributesId=" +
selectedAttributesId +
"&attributeGroupSequence=" +
attributeGroupSequence +
"&availableAttribute=" +
availableAttribute,
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function (response) {
$("#product-variation-attribute").html(response.html);
$("#attribute-variation").html(response.attributesCombination);
$("#product_variation_gallery").html(response["rawitemGalleryHtml"]);
if (response["rawitemGalleryHtml"] != "") {
$(".pgwSlideshow").pgwSlideshow({
autoSlide: false,
displayList: true,
displayControls: false,
touchControls: false,
});
$(".ps-current ul li").zoom();
}
$("#product_variation_dimension_message").hide();
$("#product_variation_dimension").html(
response["rawitemDimensionHtml"]
);
$("#product_variation_weight").html(response["weight"]);
$(".loader").removeClass("show");
$(".loader").addClass("hide");
var selected_commaseparated_attribute = commaseparated_attribute_id.split(
","
).length;
if (selected_commaseparated_attribute == gray_box_count) {
if ($(".gray-box .last").hasClass("disable_attribute")) {
$(".gray-box .last")
.removeClass("disable_attribute")
.addClass("selected_attribute");
$(".gray-box .last")
.siblings()
.removeClass("selected_attribute")
.addClass("disable_attribute");
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("li.selected_attribute:first")
.find("input")
.prop("checked", true);
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("select")
.find("option.selected_attribute:first")
.prop("selected", true);
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("li.selected_attribute:first")
.find("input")
.trigger("click");
$(".gray-box .last")
.parents("div")
.filter(".gray-box")
.siblings()
.find("select")
.find("option.selected_attribute:first")
.prop("selected", true)
.trigger("change");
}
}
getProductVariationData(
commaseparated_attribute_id,
gray_box_count,
selectedAttributesId,
productId,
variasion,
attributeGroupVisible
);
},
});
}
}
function updateDownloadButton(url) {
$("#downloadImage").attr("href", url);
}
function getProductVariationData(
commaseparated_attribute_id,
gray_box_count,
selectedAttributesId,
productId,
variasion,
attributeGroupVisible
) {
var site_url = getBaseUrl();
var selected_commaseparated_attribute = commaseparated_attribute_id.split(",")
.length;
// if (selected_commaseparated_attribute == gray_box_count) {
$("#selected_attribute").val(selectedAttributesId + ",");
$.ajax({
type: "POST",
dataType: "json",
url: site_url + "/product/getproductvariationdata",
cache: false,
data:
"commaseparated_attribute_id=" +
commaseparated_attribute_id +
"&product_id=" +
productId +
"&variasion=" +
variasion +
"&selectedAttributesId=" +
selectedAttributesId,
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function (response) {
if (response.sku != undefined) {
$("#sale_price_id").html(response["sale_price_with_currency"]);
$("#msrp_price_id").html(response["msrp_price_with_currency"]);
$("#product_variation_sku").html(response["sku"]);
$("#product_variation_shortdescription").html(
"" + response["description"] + "
"
);
$("#product_variation_bulletfeatures").html(
"" + response["bullet_features"] + "
"
);
$("#product_variation_advancedimension").html(
"" + response["advance_dimension"] + "
"
);
$("#product_tag_list").show();
if (response["tags"] != "") {
$("#product_variation_tags").html(response["tags"]);
}
$("#product_variation_dimension_message").hide();
$("#product_variation_dimension").html(
response["rawitemDimensionHtml"]
);
$("#product_variation_weight").html(response["weight"]);
$("#product_variation_gallery").html(response["rawitemGalleryHtml"]);
$("#product_variation_visible_attribute").html(
response["visibleAttributeHtml"]
);
if (response["InstallmentSetting"] != null) {
$("#product_variation_installment").html(
response["InstallmentSetting"]["installmentLable"]
);
}
$("#commaseparated_attribute_id").val(
response["commaseparated_attribute_id"]
);
$("#product-variation .addtocart").attr("disabled", false);
$("#no_variation_message").html("");
$.each(attributeGroupVisible, function (index, value) {
if ($("#attributelist-" + index).length > 0) {
$("#attributelist-" + index).html(value);
}
});
$(".pgwSlideshow").pgwSlideshow({
autoSlide: false,
displayList: true,
displayControls: false,
touchControls: false,
});
$(".ps-current ul li").zoom();
if ($("#inventory_block").length) {
var mRaw = [];
$.each(response.raw_items, function (i, item) {
mRaw.push(item.id);
});
LoadInventoryByRawItem(
Object.keys(mRaw)
.reduce(function (a, k) {
a.push("id[]" + "=" + encodeURIComponent(mRaw[k]));
return a;
}, [])
.join("&")
);
}
} else {
$("#sale_price_id").html($("#first_sale_price").val());
$.each(attributeGroupVisible, function (index, value) {
if ($("#attributelist-" + index).length > 0) {
$("#attributelist-" + index).html(value);
}
});
$("#product-variation .addtocart").attr("disabled", true);
}
$(".loader").removeClass("show");
$(".loader").addClass("hide");
},
complete: function (response) {},
});
// } else {
// $("#product-variation .addtocart").attr("disabled", true);
// $("#sale_price_id").html($("#first_sale_price").val());
// $("#msrp_price_id").html($("#first_msrp_price").val());
// $("#product_variation_installment").html(
// $("#first_installment_price").val()
// );
// }
}
function LoadInventoryByRawItem(query) {
var site_url = getBaseUrl();
$.ajax({
type: "POST",
url: site_url + "/product/getrawiteminventory",
cache: false,
data: query,
beforeSend: function () {},
success: function (responseD) {
$("#inventory_block").html(responseD);
},
complete: function (responseD) {},
});
}
window.onload = function () {
if (
$("#commaseparated_attribute_id").val() != "" &&
$("#commaseparated_attribute_id").val() != undefined
) {
var sale_price = 0;
var variasion = 0;
sale_price = $("#hdn_sale_price").val();
var commaseparated_attribute_id = "";
$.each($(".product_attribute_group_selectbox"), function () {
if ($(this).val() != "") {
variasion =
parseFloat(variasion) +
parseFloat(
$("option:selected", this).attr("attribute-price-variation")
);
commaseparated_attribute_id =
commaseparated_attribute_id + $(this).val() + ",";
}
});
var new_sale_price = parseFloat(sale_price) + parseFloat(variasion);
var site_url = getBaseUrl();
if (commaseparated_attribute_id != "") {
commaseparated_attribute_id = commaseparated_attribute_id.slice(0, -1);
}
$("#commaseparated_attribute_id").val(commaseparated_attribute_id);
var productId = $("#prdDataId").val();
$.ajax({
type: "POST",
dataType: "json",
url: site_url + "/product/getproductprice",
cache: false,
data:
"sale_price=" +
new_sale_price +
"&commaseparated_attribute_id=" +
commaseparated_attribute_id +
"&product_id=" +
productId,
success: function (response) {
if (response["sale_price"] != "") {
$("#sale_price_id").html(response["sale_price"]);
$("#msrp_price_id").html(response["msrp_price"]);
}
},
});
}
};
// textsurvey form
$("#textSurvey").attr("checked", false);
$("body").delegate("#textsurveycancel", "click", function () {
$("#textSurveyModal").modal("hide");
$("#agreetextsurvey").prop("checked", false);
});
$("body").delegate("#textsurveyaccept", "click", function () {
$("#textSurveyModal").modal("hide");
$("#textSurvey").prop("checked", true);
});
$("#textSurvey").click(function (e) {
if ($("#textSurvey").is(":checked")) {
e.preventDefault();
$("#textSurveyModal").modal("show");
$("#textSurveyModal").modal({
keyboard: false,
show: true,
backdrop: "static",
});
$("#textSurveyModal").on("hide.bs.modal", function () {});
} else {
$("#textSurvey").prop("checked", false);
}
});
// addtional invoice details
$("#checkbox_invoice").on("change", function () {
if ($("#checkbox_invoice").prop("checked") == true) {
$("#showInvoiceModal").modal("show", { backdrop: "true", keyboard: false });
}
});
$("body").delegate("#submit_invoice", "click", function (e) {
var baseUrl = getBaseUrl();
$("#invoice_same_billing").attr("checked", false);
$("#invoice_same_shipping").attr("checked", false);
$("#invoiceForm").bootstrapValidator({
excluded: ":disabled",
feedbackIcons: {
valid: "fa",
invalid: "err",
validating: "fa",
},
fields: {
invoice_first_name: {
validators: {
notEmpty: {
message: front_first_name_msg,
},
},
},
invoice_last_name: {
validators: {
notEmpty: {
message: front_last_name_msg,
},
},
},
invoice_address1: {
validators: {
notEmpty: {
message: front_address_require,
},
},
},
tax_id: {
validators: {
notEmpty: {
message: "Please Enter TaxId",
},
},
},
invoice_email: {
validators: {
notEmpty: {
message: front_email_validation,
},
emailAddress: {
message: front_email_valid_msg,
},
},
},
invoice_country_id: {
validators: {
notEmpty: {
message: front_country_err_msg,
},
},
},
invoice_city: {
validators: {
notEmpty: {
message: front_city_err_msg,
},
},
},
invoice_state_id: {
validators: {
notEmpty: {
message: front_select_state_require,
},
},
},
},
submitHandler: function (validator, form, submitButton) {},
invoice_zip: {
validators: {
/* notEmpty: {
message: front_postcode_require,
},*/
stringLength: {
max: 15,
message: front_postcode_valid,
},
},
/* callback: {
message: front_postcode_require,
callback: function (value, validator, $field) {
var reguser = $("#regflag").val();
if (reguser != 1 && $("#invoice_zip").val()=='') {
return false;
}
return true;
}
}*/
}
});
});
$("body").on("success.form.bv", "#invoiceForm", function (event) {
event.preventDefault();
event.stopImmediatePropagation();
$("#submit_invoice").attr("disabled", false);
var id = $("#invoice_oderid").val();
// alert(id);
var baseUrl = getBaseUrl();
var formData = $("#invoiceform").serialize();
$.ajax({
type: "POST",
url: baseUrl + "/order/invoicedata",
cache: false,
data: formData,
beforeSend: function () {
$("body").Wload({ text: "Sending Mail..." });
},
success: function (response) {
if (response == "true") {
$("body").Wload("hide", { time: 5 });
$("#showInvoiceModal").modal("hide");
$("#invoiceForm").data("bootstrapValidator").resetForm();
$("#showInvoiceModal")[0].reset();
} else {
$("#showInvoiceModal").modal("show");
$("#invoiceForm").data("bootstrapValidator").resetForm();
}
},
});
});
$("#invoice_same_shipping").on("change", function() {
if ($(this).is(":checked")) {
$("#invoice_same_billing").attr("checked", false);
$("#invoice_first_name").val($("#shipping_firstName").val());
$("#invoice_last_name").val($("#shipping_lastName").val());
$("#invoice_company_name").val($("#shipping_companyName").val());
$("#invoice_email").val($("#shipping_emailid").val());
$("#invoice_address1").val($("#form_shipping_address1").val());
$("#invoice_address2").val($("#form_shipping_address2").val());
$("#invoice_city").val($("#form_shipping_city").val());
$("#invoice_country_id").val($("#shipping_countryId").val());
$("#invoice_zip").val($("#form_shipping_zipcode").val());
$("#invoice_state_id").val($("#form_shipping_stateId").val());
$("#invoice_phone").val($("#shipping_contact").val());
getCheckoutCity(
$("#invoice_state_id").val(),
$("#form_shipping_city").val(),
"invoice",
"change"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_first_name]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_last_name]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_email]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_address1]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_city]"
);
/* $("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_zip]"
);*/
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_state_id]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_country_id]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_phone]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_tax_id]"
);
} else {
this.form.reset();
}
});
$("#invoice_same_billing").on("change", function() {
if ($(this).is(":checked")) {
$("#invoice_same_shipping").attr("checked", false);
$("#invoice_first_name").val($("#billing_firstName").val());
$("#invoice_last_name").val($("#billing_lastName").val());
$("#invoice_company_name").val($("#billing_companyName").val());
$("#invoice_email").val($("#billing_emailid").val());
$("#invoice_address1").val($("#form_billing_address1").val());
$("#invoice_address2").val($("#form_billing_address2").val());
$("#invoice_city").val($("#form_billing_city").val());
$("#invoice_country_id").val($("#billing_countryId").val());
$("#invoice_zip").val($("#form_billing_zipcode").val());
$("#invoice_state_id").val($("#form_billing_stateId").val());
$("#invoice_phone").val($("#billing_contact").val());
getCheckoutCity(
$("#invoice_state_id").val(),
$("#form_billing_city").val(),
"invoice",
"change"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_first_name]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_last_name]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_email]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_address1]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_city]"
);
/*$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_zip]"
);*/
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_state_id]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_country_id]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_phone]"
);
$("#invoiceFrom").bootstrapValidator(
"revalidateField",
"form[invoice_tax_id]"
);
} else {
this.form.reset();
}
});
$("body").delegate("#invoice_country_id", "change", function () {
var invoice_country = $("#invoice_country_id").val();
getCheckoutState(invoice_country, (selectedState = ""), "invoice", "change");
var invoice_state = $("#invoice_state_id").val();
});
$("body").delegate("#invoice_state_id", "change", function (e) {
e.preventDefault();
e.stopImmediatePropagation();
var invoice_state = $("#invoice_state_id").val();
getCheckoutCity(invoice_state, (selectedCity = ""), "invoice", "change");
var invoice_country = $("#invoice_country_id").val();
var invoice_city = $("#invoice_city").val();
});
$("body").delegate("#submit_invoice", "click", function (e) {
if ($("#invoiceFrom").size() > 0) {
$("#invoiceFrom").bootstrapValidator({
excluded: ":disabled",
feedbackIcons: { valid: "fa", invalid: "err", validating: "fa" },
fields: {
"form[invoice_first_name]": {
validators: { notEmpty: { message: front_first_name_msg } },
},
"form[invoice_last_name]": {
validators: { notEmpty: { message: front_last_name_msg } },
},
"form[invoice_address1]": {
validators: { notEmpty: { message: front_address_require } },
},
"form[invoice_tax_id]": {
validators: {
notEmpty: { message: front_taxid_require },
integer: { message: front_taxid_valid },
},
},
"form[invoice_email]": {
validators: {
notEmpty: { message: front_email_validation },
emailAddress: { message: front_email_valid_msg },
},
},
"form[invoice_country_id]": {
validators: { notEmpty: { message: front_country_err_msg } },
},
"form[invoice_city]": {
validators: { notEmpty: { message: front_city_err_msg } },
},
"form[invoice_state_id]": {
validators: { notEmpty: { message: front_select_state_require } },
},
/*"form[invoice_zip]": {
validators: {
callback: {
message: front_postcode_require,
callback: function (value, validator, $field) {
var reguser = $("#regflag").val();
if (reguser != 1 && $("#invoice_zip").val()=='') {
return false;
}
return true;
}
}
}
},*/
"form[invoice_phone]": {
validators: {
notEmpty: { message:front_phone_number_msg },
stringLength: {
min: 10,
message: front_phone_number_length_valid_msg,
},
regexp: {
regexp: /^[^-\s][0-9()+-\s]+(?:,\d+)*$/i,
message: front_phone_number_valid_msg,
},
},
},
},
submitHandler: function (validator) {},
});
}
if (
$("#invoiceFrom").bootstrapValidator("validate").has(".has-error")
.length === 0
) {
var baseUrl = getBaseUrl();
var formData = $("#invoiceFrom").serialize();
$.ajax({
type: "POST",
url: baseUrl + "/order/invoicedata",
cache: false,
data: formData,
success: function (response) {
if (response) {
$("#hdn_invoice_form_data").val(response);
}
$("#showInvoiceModal").modal("hide");
//$("#invoiceForm").data('bootstrapValidator').resetForm();
//$("#showInvoiceModal")[0].reset();
},
});
} else {
return false;
}
});
/*function showAbandonedCartModal() {
if ($('#abandonedCartDataModal').length > 0) {
$('#abandonedCartDataModal').modal('show');
$('#abandoned_cart_data_submit').click(function (event) {
$("#abandonedcartfrm").data('bootstrapValidator').revalidateField('abandoned_email');
event.preventDefault();
event.stopImmediatePropagation();
var baseUrl = getBaseUrl();
var formData = $("#abandonedcartfrm").serialize();
$.ajax({
type: "POST",
dataType: "json",
url: baseUrl + "/abandonedcart/getemailabandonedcart",
cache: false,
data: formData,
success: function (response) {
if (response > 0) {
$('#abandonedCartDataModal').modal('hide');
return true;
} else {
return false;
}
}
});
});
}
}*/
//REN12
function showAbandonedCartModalopen() {
if ($("#abandonedCartDataModal").length > 0) {
$("#abandonedCartDataModal").modal("show");
var baseUrl = getBaseUrl();
$.ajax({
url: baseUrl + "/abandonedcartmodal",
success: function (response) {
var obj = JSON.parse(response);
$("#abandonedcart_title").html(obj.title);
$("#abandonedcart_body").html(obj.description);
$("#abandoned_cart_data_submit").click(function (event) {
$("#abandonedcartfrm")
.data("bootstrapValidator")
.revalidateField("abandoned_email");
event.preventDefault();
event.stopImmediatePropagation();
var baseUrl = getBaseUrl();
var formData = $("#abandonedcartfrm").serialize();
$.ajax({
type: "POST",
dataType: "json",
url: baseUrl + "/abandonedcart/getemailabandonedcart",
cache: false,
data: formData,
success: function (response) {
if (response > 0) {
$("#abandonedCartDataModal").modal("hide");
return true;
} else {
return false;
}
},
});
});
},
});
}
}
$("#abandonedCartDataModal").on("shown.bs.modal", function (e) {
$("#abandonedcartfrm").bootstrapValidator({
feedbackIcons: { valid: "fa", invalid: "err", validating: "fa" },
fields: {
abandoned_email: {
validators: {
notEmpty: { message: front_email_validation },
emailAddress: { message: front_email_valid_msg },
},
},
},
submitHandler: function (validator, form, submitButton) {},
});
});
$("#termsConditions").on("click", function () {
var url = site_url1 + "cmspageotherContent/TermsandConditions";
$.ajax({
url: url,
type: "post",
success: function (result) {
if (result) {
$("#terms_conditions").modal("hide");
$("#terms_conditions").modal("toggle");
$("#terms_conditions .modal-body").html(result);
} else {
$("#terms_conditions").modal("hide");
swal({
title: front_warning,
text: front_warning_msg,
type: "info",
confirmButtonText: front_ok,
});
}
return false;
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
},
});
});
$('#frmcheckout :input').change(function(){
var bill_diff_address = 0;
if ($("#chkbilladdress").prop("checked") == true || $('#selected_shipping_method_slug').val() == 'instorepickup') {
bill_diff_address = 1;
}
var baseUrl = getBaseUrl();
if(bill_diff_address == 0 && ($.trim($("#shipping_firstName").val())=="" && $.trim($("#shipping_lastName").val())=="" && $.trim($("#form_shipping_address1").val())=="" && $.trim($("#shipping_emailid").val())=="" && $.trim($("#shipping_contact").val())=="")){
/*As Bill to diff address not checked and the Type is OTHER then Instore so billing address and shipping address are same*/
var form_ship_data =
"&ship_first_name=" +
$("#billing_firstName").val() +
"&ship_middle_name=" +
$("#billing_middleName").val() +
"&ship_last_name=" +
$("#billing_lastName").val() +
"&ship_company_name=" +
$("#billing_companyName").val() +
"&ship_address1=" +
$("#form_billing_address1").val() +
"&ship_address2=" +
$("#form_billing_address2").val() +
"&ship_email=" +
$("#billing_emailid").val() +
"&ship_phone=" +
$("#billing_contact").val() +
"&ship_fax=" +
$("#billing_fax").val() +
"&shipping_countryId=" +
$("#billing_countryId").val() +
"&shipping_stateId=" +
$("#form_billing_stateId").val() +
"&shipping_cityId=" +
$("#formBillingCity").val() +
"&shipping_zipcode=" +
$("#form_billing_zipcode").val();
//alert(form_ship_data);
}else{
if($.trim($("#shipping_firstName").val())=="" && $.trim($("#shipping_lastName").val())=="" && $.trim($("#form_shipping_address1").val())=="" && $.trim($("#shipping_emailid").val())=="" && $.trim($("#shipping_contact").val())==""){
/*As Bill to Diff address are not checked but user select option "In store Pickup" so once user make entries in the
form while select "In store option" at that time we need to copied the billing Information data to the Delivery Address
So once user will change from "In store Option" to any other shipping option the "Delivery Address" has already copied the data of billing address.
29-05-23*/
var form_ship_data =
"&ship_first_name=" +
$("#billing_firstName").val() +
"&ship_middle_name=" +
$("#billing_middleName").val() +
"&ship_last_name=" +
$("#billing_lastName").val() +
"&ship_company_name=" +
$("#billing_companyName").val() +
"&ship_address1=" +
$("#form_billing_address1").val() +
"&ship_address2=" +
$("#form_billing_address2").val() +
"&ship_email=" +
$("#billing_emailid").val() +
"&ship_phone=" +
$("#billing_contact").val() +
"&ship_fax=" +
$("#billing_fax").val() +
"&shipping_countryId=" +
$("#billing_countryId").val() +
"&shipping_stateId=" +
$("#form_billing_stateId").val() +
"&shipping_cityId=" +
$("#formBillingCity").val() +
"&shipping_zipcode=" +
$("#form_billing_zipcode").val();
}else{
/* If user already make entries in the "Delivery Address" and then change the Shipping option then we do not change billing info to the delivery address
As user already make entry to that form as user just change the Shipping option 29-05-23 */
var form_ship_data =
"&ship_first_name=" +
$("#shipping_firstName").val() +
"&ship_middle_name=" +
$("#shipping_middleName").val() +
"&ship_last_name=" +
$("#shipping_lastName").val() +
"&ship_company_name=" +
$("#shipping_companyName").val() +
"&ship_address1=" +
$("#form_shipping_address1").val() +
"&ship_address2=" +
$("#form_shipping_address2").val() +
"&ship_email=" +
$("#shipping_emailid").val() +
"&ship_phone=" +
$("#shipping_contact").val() +
"&ship_fax=" +
$("#shipping_fax").val() +
"&shipping_countryId=" +
$("#shipping_countryId").val() +
"&shipping_stateId=" +
$("#form_shipping_stateId").val() +
"&shipping_cityId=" +
$("#formShippingCity").val() +
"&shipping_zipcode=" +
$("#form_shipping_zipcode").val();
}
}
var form_bil_data =
"&bil_first_name=" +
$("#billing_firstName").val() +
"&bil_middle_name=" +
$("#billing_middleName").val() +
"&bil_last_name=" +
$("#billing_lastName").val() +
"&bil_company_name=" +
$("#billing_companyName").val() +
"&bil_address1=" +
$("#form_billing_address1").val() +
"&bil_address2=" +
$("#form_billing_address2").val() +
"&bil_email=" +
$("#billing_emailid").val() +
"&bil_phone=" +
$("#billing_contact").val() +
"&bil_fax=" +
$("#billing_fax").val() +
"&billing_countryId=" +
$("#billing_countryId").val() +
"&billing_stateId=" +
$("#form_billing_stateId").val() +
"&billing_cityId=" +
$("#formBillingCity").val() +
"&billing_zipcode=" +
$("#form_billing_zipcode").val();
var other_data = "&bill_diff_address=" + bill_diff_address + '&shipping_method_slug=' + $('#selected_shipping_method_slug').val() + '&preferred_range_from=' + $('#rangeFrom').val() + '&preferred_range_to=' + $('#rangeTo').val() + '&sales_person=' + $('#form_salesPerson').val();
$.ajax({
type: "POST",
cache: false,
url: baseUrl + "/shoppingcart/saveformdata",
data: form_ship_data + form_bil_data + other_data,
success: function(response) {
},
});
});
function availableProductToCheckout(){
var baseUrl = getBaseUrl();
$.ajax({
type: "POST",
url: baseUrl + "/shoppingcart/available-product-to-checkout",
dataType: 'json',
beforeSend: function () {
$(".loader").removeClass("hide");
$(".loader").addClass("show");
},
success: function(response) {
$(".loader").removeClass("show");
$(".loader").addClass("hide");
if(response.status == 1){
swal({
title: 'Info',
text: response.message,
type: "info",
confirmButtonText: front_ok,
}, function(isConfirm){
if(isConfirm){
//location.href="/checkout";
location.reload(true);
}
});
}else{
location.href="/checkout";
}
},
});
}
$("#checkbox6-555").on("change", function () {
if ($("#checkbox6-555").prop("checked") == true && $("#invbx").val()==1) {
$("#showInvoiceModal").modal("show", { backdrop: "true", keyboard: false });
}
});
$("#cancel_invoice").click(function(){
$("#showInvoiceModal").modal("hide");
$("#checkbox_invoice").attr("checked", false);
if ($("#checkbox6-555").prop("checked") == true && $("#invbx").val()==1) {
$("#checkbox6-555").attr("checked", false);
}
$("#invoiceFrom")[0].reset();
$("#invoiceFrom").data("bootstrapValidator").resetForm();
$("#invoiceFrom").trigger("reset");
});
$('input[type=radio][name=invoice_popup]').on('click', function() {
if (this.value == 'invoice') {
$("#showInvoiceModal").modal("show", { backdrop: "true", keyboard: false });
}
});
/*BOF code for Tiered Products*/
$('input:checkbox.tcheckbx').on('change', function() {
var id=$(this).attr("id");
if (this.checked){
$("#qty_"+id).val(1);
}else{
$("#qty_"+id).val(0);
}
calculateWithQty();
});
$(".tieqty").change(function() {
var chkid=$(this).attr("id").replace("qty_", "");
if($(this).val()==0){
$("#"+chkid).prop("checked",false);
}else{
$("#"+chkid).prop("checked",true);
}
calculateWithQty();
});
$(document).on('change','#prdqty',function(){
/*var caltsale,caltmsrp;
caltsale = caltmsrp = 0;
update_price_html(caltsale,caltmsrp);*/
var chkid=$(this).attr("id").replace("qty_", "");
$("#"+chkid).prop("checked",true);
calculateWithQty();
});
function calculateWithQty(){
var totsale = totmsrp = 0;
$(".tieqty").each(function() {
var getsale = $(this).attr("data-sale-price");
var getmsrp = $(this).attr("data-msrp-price"); // gets id
var getQty = $(this).val();
if(getQty > 0){
totsale += (getQty*getsale);
totmsrp += (getQty*getmsrp);
}
});
update_price_html(totsale,totmsrp);
}
/*function update_price_html_old(tsale,tmsrp){
var cursymbol,prdqty,msrp,sale,calmsrp,calsale,finalsale;
cursymbol='';
prdqty=msrp=sale=calmsrp=calsale=tqty=tsp=tmp=caltmsrp=caltsale=finalsale=0;
cursymbol= $("#hdn_currency").val();
prdqty= $("#prdqty").val();
msrp= $("#prod_msrp").val();
sale= $("#prod_sale").val();
if(tsale > 0 && tmsrp > 0){
calmsrp= (prdqty*msrp)+tmsrp;
calsale= (prdqty*sale)+tsale;
}else{
calmsrp= prdqty*msrp;
calsale= prdqty*sale;
}
finalsale=checkTieDiscount(calsale);
$('.msrp span').html(cursymbol+calmsrp.toFixed(2));
$('.c-price').html(cursymbol+finalsale.toFixed(2));
}
function checkTieDiscount_old(price){
var discount= $("#discount").val();
var no_of_pieces=$("#no_of_pieces").val();
var countCheckbox =0;
if(discount > 0){
$('.tcheckbx').each(function() {
countCheckbox = $('.tcheckbx').filter(':checked').length;
});
if(countCheckbox >= no_of_pieces){
var tie_disc=(price*discount/100);
$("#tie_discount").val(tie_disc);
price=price-(price*discount/100);
}else{
$("#tie_discount").val(0);
}
}
return price;
}*/
function update_price_html(tsale,tmsrp){
var cursymbol,prdqty,msrp,sale,calmsrp,calsale,finalsale;
cursymbol='';
prdqty=msrp=sale=calmsrp=calsale=tqty=tsp=tmp=caltmsrp=caltsale=finalsale=0;
cursymbol= $("#hdn_currency").val();
prdqty= $("#prdqty").val();
msrp= $('#tieElement').data('msrp');
sale= $('#tieElement').data('sale');
if(tsale > 0 && tmsrp > 0){
calmsrp= (prdqty*msrp)+tmsrp;
calsale= (prdqty*sale)+tsale;
}else{
calmsrp= prdqty*msrp;
calsale= prdqty*sale;
}
finalsale=checkTieDiscount(calsale);
$('.msrp span').html(cursymbol+calmsrp.toFixed(2));
$('.c-price span').html(cursymbol+finalsale.toFixed(2));
var discount= $('#tieElement').data('p-disc');
$("#saving_amount").remove();
if(calsale > finalsale){
$(".prod_price ul").append(''+front_cart_was+': '+cursymbol+calsale.toFixed(2)+' '+savings+' '+discount+'%');
}
}
function checkTieDiscount(price){
var discount= $('#tieElement').data('p-disc');
var no_of_pieces= $('#tieElement').data('pieces');
var countCheckbox =0;
if(discount > 0){
$('.tcheckbx').each(function() {
countCheckbox = $('.tcheckbx').filter(':checked').length;
});
if(countCheckbox >= no_of_pieces){
var tie_disc=(price*discount/100);
$("#tieElement").attr('data-tie-disc', tie_disc);
price=price-(price*discount/100);
}else{
$("#tieElement").attr('data-tie-disc', 0);
}
}
return price;
}
function disabledMsg(id,msg){
var MsgArray ={ 0: 'Sorry, this product is not available for add to cart.',
2: 'The product you have added to your shopping cart will be available for delivery after.',
3: 'At this time, there is no ETA for this product.' };
var mainprodid=$(".addtocart").attr("data-name");
if(id==mainprodid){
$(".addtocart").prop("disabled",true);
$("#prdqty").val(1);
$("#prdqty").prop("disabled", true);
$("#msg_"+id).text(MsgArray[msg]);
}else{
var showmsg=MsgArray[msg];
$("#msg_"+id).text(showmsg);
$("#"+id).prop("checked", false);
$("#"+id).prop("disabled", true);
$("#qty_"+id).val(0);
$("#qty_"+id).prop("disabled", true);
}
}
function checkAllQty(arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] != 0) {
return false; // Return false if any element is not zero
}
}
return true; // Return true if all elements are zero
}
function showSwetAlert(){
var add_to_cart_alert = "An error occurred during the process of adding items to your cart.";
swal({
title: front_shopping_cart_label,
text: add_to_cart_alert,
type: "warning",
allowOutsideClick: true,
allowEscapeKey: true,
},
function(){ }
);
calculateWithQty();
}
/*EOF code for Tiered Products*/