$(document).ready(function(){
$('#menu').slicknav();
$( ".accordion" ).accordion({
heightStyle: "content"
});
//auto complete for product
$(".txt_search").autocomplete({
source: function( request, response ) {
$.ajax({
url: "_models/functions/products_ajax_functions.php?page=getSearchJson&val="+$('.txt_search').val(),
success: function( data ) {
response(eval( data ));
}
});
},
minLength: 3,
select: function( event, ui ) {
$('.txt_search').val(ui.item.label);
$('#searchForm').submit();
},open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
$('.ui-menu').width(300);
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("
")
.data("item.autocomplete", item)
.css({"margin":"1px 0",
"height": "85px",
"padding":"5px"})
.append("" +
"
" +
"

" +
"
" +
"
"+item.name+"
"+item.oldPrice+"
"+item.newPrice+"
" +
"
")
.appendTo(ul);
};
/* $('.txt_search').keyup(function(){
srch = $('.txt_search').val();
if(srch.length>=3){
productSearch(srch);
}
});*/
});
function productSearch(){
//not in use,, built for get product for search
srch = $('.txt_search').val();
$.ajax({
type: 'GET',
url: '_models/functions/products_ajax_functions.php?page=getSearchJson',
data : {val:srch}
}).done(function(data){
if(data=='[]'){
productSearchAutoComplete(data);
}else{
productSearchAutoComplete(data);
}
});
}
function productSearchAutoComplete(data){
//products load after country select
var availableTags = eval(data);
$(".txt_search").autocomplete({
source: function( request, response ) {
$.ajax({
url: "_models/functions/products_ajax_functions.php?page=getSearchJson",
dataType: "POST",
data : {val:$('.txt_search').val()},
success: function( data ) {
response( data );
}
});
},
minLength: 0,
select: function( event, ui ) {
$('.txt_search').val(ui.item.label);
}
}).on('focus : click', function(event) {
$(this).autocomplete("search", "");
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("")
.data("item.autocomplete", item)
.css({"margin":"1px 0",
"height": "70px",
"padding":"5px"})
.append("" +
"
" +
"

" +
"
" +
"
"+item.label+"
"+item.oldPrice+"
"+item.newPrice+"
" +
"
")
.appendTo(ul);
};
}
//Create Link
function link(id){
//document.location.href="?product="+url;
catP = getParam('cat');
search = getParam('s');
var params = "";
if(catP=="" && search == ""){
params = "product="+id;
}else if(catP !="" && search == ""){
params = "cat="+catP+"&product="+id;
}else if(catP =="" && search != ""){
params = "s="+search+"&product="+id;
}
history.pushState(null, "Product ", "?"+params);
}
function blankLink(){
//document.location.href="?product="+url;
catP = getParam('cat');
search = getParam('s');
var params = "";
if(catP=="" && search == ""){
params = ""
}else if(catP !="" && search == ""){
params = "cat="+catP;
}else if(catP =="" && search != ""){
params = "s="+search;
}
history.pushState(null, "Product ","?"+params);
}
//get Parameter Value
function getParam ( sname )
{
var params = location.search.substr(location.search.indexOf("?")+1);
var sval = "";
params = params.split("&");
// split param and value into individual pieces
for (var i=0; iqtyTotal){
return false;
}
$("#cartLoading").slideDown(500);
$.ajax({
type: "POST",
url : "_models/functions/products_ajax_functions.php?page=AddPlusToCart",
data: { cartId:cartId}
}).done(function(data) {
$("#cartLoading").slideUp(500);
if(data=='1' || data==''){
updateCartNoOnWeb();
qty = eval(qty+1);
cartProductQtyUpdate(cartId,qty);
sumSingleProduct(cartId,qty);
}else{
jAlertifyAlert(data);
}
});
}
function minusFromCart(ths,cartId){
qty = parseFloat($('#tr_'+cartId).find('.pQty').text());
if(qty==0 || qty==1 || qty <2){
return false;
}
$("#cartLoading").slideDown(500);
$.ajax({
type: "POST",
url : "_models/functions/products_ajax_functions.php?page=minusFromCart",
data: { cartId:cartId}
}).done(function(data) {
$("#cartLoading").slideUp(500);
if(data=='1' || data==''){
updateCartNoOnWebMinus();
qty = eval(qty-1);
cartProductQtyUpdate(cartId,qty);
sumSingleProduct(cartId,qty);
}else{
jAlertifyAlert(data);
}
});
}
function cartProductRemove(ths,cartId){
qty = parseFloat($('#tr_'+cartId).find('.pQty').text());
$('.pGrandTotal,.pTotalWeight').html('Loading...');
$("#cartLoading").slideDown(500);
$.ajax({
type: "POST",
url : "_models/functions/products_ajax_functions.php?page=cartProductRemove",
data: { cartId:cartId}
}).done(function(data) {
$("#cartLoading").slideUp(500);
if(data=='1' || data==''){
updateCartNoOnWebRemove(qty);
remove_tr(ths,0);
setTimeout(function(){
totalPrice();
totalWeight();
},1200);
}else{
jAlertifyAlert(data);
}
});
}
function totalPrice(){
total = 0;
$('.pTotalPrice').each(function(k,v){
price = parseFloat($(this).text());
total = eval(total+price);
});
total = Math.round(total*100)/100;
$('.pGrandTotal').text(total);
$('.pGrandTotal').attr('data-total',total);
tax2(total);
}
function cartProductQtyUpdate(cartId,qty){
$('#tr_'+cartId).find('.pQty').text(qty);
ActualPrice = $('#tr_'+cartId).attr('data-price');
total = eval(ActualPrice*qty);
total = Math.round(total*100)/100;
$('#tr_'+cartId).find('.pTotalPrice').text(total);
totalPrice();
pWeight(cartId,qty);
}
function cartContinue(){
$('.paymentOptionDiv').slideDown(500);
/* $("#cartLoading").slideDown(500);
$.ajax({
type: "POST",
url : "cartContinue.php"
}).done(function(data) {
$("#cartLoading").slideUp(500);
$("#cartContinue ").html(data);
});*/
}
function pWeight(cartId,qty){
ActualWeight = $('#tr_'+cartId).attr('data-weight');
total = eval(ActualWeight*qty);
total = Math.round(total*100)/100;
$('#tr_'+cartId).find('.product_weight').val(total);
$('#tr_'+cartId).find('.pWeight').text(total);
totalWeight();
}
function totalWeight(){
total = 0;
$('.product_weight').each(function(k,v){
weight = parseFloat($(this).val());
total = eval(total+weight);
});
total = Math.round(total*100)/100;
$('.pTotalWeight').text(total);
$('.totalWeightInput').val(total);
}
function shippingPriceWidget(){
$('.cartSubmit1').attr('disabled','true');
$("#cartLoading").slideDown(500);
deliverCountry = $('#shippingWidget').val();
storeCountry = $('#storeCountryShippingWidget').val();
$.ajax({
type: "POST",
url: "admin/order/order_ajax.php?page=shippingPrice",
data: { storeCountry:storeCountry,deliverCountry:deliverCountry},
success: function (response) {
shippingData = ($.parseJSON(response)); // receiveing json
if(shippingData.find=='1'){
shp_int = shippingData.shp_int;
shp_weight = shippingData.shp_weight;
shp_price = shippingData.shp_price;
if(shp_int=='0'){
jAlertifyAlert('Its Look Like Shipping Stop In Receiver Country '+shp_int,'Shipping Error');
return false;
}
if($.isNumeric( shp_price )){
var orderPrice = parseFloat($('.pGrandTotal ').attr('data-total'));
var weight = parseFloat($('.totalWeightInput').val());
var unitWeight = Math.ceil(weight/shp_weight);
var shippingPrice = parseFloat(shp_price);
shippingPrice = eval(shippingPrice*unitWeight);
var total = eval(orderPrice+shippingPrice);
$('.pGrandTotal ').text(total).addClass('btn-danger');
var priceCode =$('#priceCodeShippingWidget').val();
$('.pHippingPriceTemp').text(shippingPrice+" "+priceCode);
$('.cartSubmit1').removeAttr('disabled');
}
}else{
jAlertifyAlert('Its Look Like Shipping Is Not Available In Receiver Country','Shipping Error');
}
$("#cartLoading").slideUp(500);
}
});
intshp = isInternationalShippingWidget();
if(intshp==false){
$('.cartSubmit1').attr('disabled','true');
}
}
function isInternationalShippingWidget(){
chk=true;
receiverCountry = $("#shippingWidget").val();
storeCounntry = $("#storeCountryShippingWidget").val();
$('.interShipping').each(function(i,data){
$(this).closest('tr').find('td').removeClass('btn-danger cartProductHighLight');
if(receiverCountry==storeCounntry){
return true;
}else if($(this).val() == '0'){
tr=$(this).closest('tr').find('td').addClass('btn-danger cartProductHighLight');
chk=false;
}
});
if(!chk){
notification("Shipping Error","Highlight Product Are not ship in receiver country.","btn-danger");
return false;
}
return chk;
}
//Scroll product load
moreProduct = true;
load = false;
$(document).scroll(function() {
if($('.iHaveProducts').height()- $(window).height() < $(window).scrollTop() && moreProduct==true && load==false) {
load = true;
limitFrom = parseInt($('#queryLimit').val());
if(limitFrom=='' || isNaN(limitFrom)){
return false;
}
limit = parseInt($('#queryLimit').attr('data-id'));
limitTo = eval(limitFrom+limit);
temp = ''+loading_progress()+'
';
$('.iHaveProducts').append(temp);
q_tempTable = $("#q_tempTable").val();
$.ajax({
type: "POST",
url : "_models/functions/products_ajax_functions.php?page=more_product",
data: { id:q_tempTable,limitFrom:limitFrom,limitTo:limitTo,limit:limit}
}).done(function(data) {
load = false;
$(".loadingDivTemp").remove();
if(data=='0' || data==''){
moreProduct = false;
}else{
$('#queryLimit').val(limitTo);
$('.iHaveProducts').append(data);
}
});
}
});