<script>
<? //* =============================== Add To Cart ====================================	*// ?>				
<? // add product in cart ?>
function add(id,sid) {
    var p_current_price = $('#p_current_price_'+id).val();
    var p_old_price = $('#p_old_price_'+id).val();
    var p_name=$('#p_name_'+id).val();
    var size_id = $('#size_id_'+id).val();
    var color_id = $('#color_id_'+id).val();
    var color_name = $('#color_name_'+id).val();
    var size_name = $('#size_name_'+id).val();
    var p_featured_photo=$('#p_featured_photo_'+id).val();
    var p_qty = $('#qty2_'+sid).val();
    $('#qty_'+sid).val(p_qty);
    var p_qty_stock = parseInt($('#qty2_'+sid).attr('qty'));
    
    $('#spname').html(p_name);
    
    // store add to cart
    var i = localStorage.getItem("cart");
    if(i==null){
        product_add=false;
    }
    else{
        
        var product_add = getval(sid);
    }
    
    // alert(product_add);
    if(product_add==false){
        if(localStorage.getItem("cart")==null){
            var i1 = 1;
        }
        else{
            var i1 = parseInt(localStorage.getItem("cart"));
            var i1 = i1+1;
        }
        
        localStorage.setItem("cart", i1);
        localStorage.setItem("cart_history", i);
        let products = [];
        if(localStorage.getItem('products')){
            products = JSON.parse(localStorage.getItem('products'));
        }
        products.push({
            'productId' : id+size_id+color_id,
            cart_p_id : id,
            cart_size_id : size_id,
            cart_color_id : color_id,
            cart_color_name : color_name,
            qty_id : i,
            cart_size_name : size_name,
            cart_p_qty : p_qty,
            cart_p_current_price : p_current_price,
            cart_p_old_price : p_old_price,
            cart_p_name : p_name,
            image : p_featured_photo
        });
        localStorage.setItem('products', JSON.stringify(products));
        
        
            <?php 
            if(basename($_SERVER['PHP_SELF'])=='cart.php' || basename($_SERVER['PHP_SELF'])=='checkout.php'){ ?>
            //     document.getElementById("cart_total_"+sid).innerHTML=gettotalprice(sid).toFixed(2);
            // document.getElementById("sub_total").innerHTML=getsubtotalprice(sid).toFixed(2);
            <?php } ?>
            // document.getElementById("cart_total").innerHTML='&#8377;'+getsubtotalprice(sid).toFixed(2);
            
        // $('#closes').css('display','block'); 
        $("#hide_A"+sid).css('display','flex'); 
        $("#hide_B"+sid).hide();
       
    }
    else{
        alert('This Product is Already Added.')
    }
viewProduct();
SetData();
}
</script>

<script>
<? //* =============================== Add To Wishlist ====================================	*// ?>				
<? // add wishlist in cart ?>
function add_to_wishlist(id,sid) {
    var p_current_price = $('#p_current_price_'+id).val();
    var p_old_price = $('#p_old_price_'+id).val();
    var p_name=$('#p_name_'+id).val();
    var size_id = $('#size_id_'+id).val();
    var color_id = $('#color_id_'+id).val();
    var color_name = $('#color_name_'+id).val();
    var size_name = $('#size_name_'+id).val();
    var p_featured_photo = $('#p_featured_photo_'+id).val();
    var p_qty = $('#qty2_'+sid).val();
    $('#qty_'+sid).val(p_qty);
    var p_qty_stock = parseInt($('#qty2_'+sid).attr('qty'));
    // $("#wish_hide_A"+sid).toggleClass("active");
    
    // store add to wishlist
    var i = localStorage.getItem("wishlist");
    if(i==null){
        product_add=false;
    }
    else{
        
        var product_add = wish_check(sid);
    }
    
    // alert(product_add);
    if(product_add==false){
        if(localStorage.getItem("wishlist")==null){
            var i1 = 1;
        }
        else{
            var i1 = parseInt(localStorage.getItem("wishlist"));
            var i1 = i1+1;
        }
        
        localStorage.setItem("wishlist", i1);
        localStorage.setItem("wishlist_history", i);
        let wish_list = [];
        if(localStorage.getItem('wish_list')){
            wish_list = JSON.parse(localStorage.getItem('wish_list'));
        }
        wish_list.push({
            'productId' : id+size_id+color_id,
            cart_p_id : id,
            cart_size_id : size_id,
            cart_color_id : color_id,
            cart_color_name : color_name,
            qty_id : i,
            cart_size_name : size_name,
            cart_p_qty : p_qty,
            cart_p_current_price : p_current_price,
            cart_p_old_price : p_old_price,
            cart_p_name : p_name,
            image : p_featured_photo
        });
        localStorage.setItem('wish_list', JSON.stringify(wish_list));
        
        $("#wish_hide_A"+sid).css('display','flex'); 
        $("#wish_hide_A"+sid).addClass("active");
       
    }
    else{
        remove_wish_Item(sid);
    }
}
</script>


<script>
function remove_wish_Item(unique){
            
    var i = localStorage.getItem("wishlist");
    var i_ = localStorage.getItem("wishlist_history");
    
    // removing product from localstorage
    let storageProducts = JSON.parse(localStorage.getItem('wish_list'));
    let wish_list = storageProducts.filter(product => product.productId != unique);
    localStorage.setItem('wish_list', JSON.stringify(wish_list));

    // response for site
    $("#wish_hide_A"+unique).toggleClass("active");
    // $("#wishdel_"+unique).remove();
    
    // setting wishlist qty
    if(i !=0){ localStorage.setItem("wishlist", i-1); }
    var i2 = localStorage.getItem("wishlist");
    if(i2 == 0){ localStorage.setItem("wishlist_history", 0); }
    
    // loadwishlist();
}
</script>


<script>
// plus quantity in cart
function plus(ida,sida) {
    alert(ida);
    alert(sida);

// quantity update
    var x = parseInt($('#qty_' + sida).attr('qty'));
    var qty_id = parseInt($('#qty_' + sida).attr('qty_id'));
    var a = parseInt($('#qty_' + sida).val());
    var b = parseInt(1);
    var c = parseInt(a + b);
    alert(a);
    /*if (a == x) {
        alert('Out Of Stock.');
    }
    else
    {
        
        //  data for quantity update
        
            let storageProducts1 = JSON.parse(localStorage.getItem('products'));
            let products1 = storageProducts1.filter(product1 => product1.productId == sida);
            products1[0].cart_p_qty=c;
            
            let storageProducts = JSON.parse(localStorage.getItem('products'));
            let products = storageProducts.filter(product => product.productId != sida);
            products.push(products1[0]);
            localStorage.setItem('products', JSON.stringify(products));
            
            $('#qty_' + sida).val(parseInt(c));
            
        
            <?php 
            if(basename($_SERVER['PHP_SELF'])=='cart.php' || basename($_SERVER['PHP_SELF'])=='checkout.php'){ ?>
            // SetData();
            //     document.getElementById("cart_total_"+sida).innerHTML=gettotalprice(sida).toFixed(2);
            // document.getElementById("sub_total").innerHTML=getsubtotalprice(sida).toFixed(2);
            <?php } ?>
            // document.getElementById("cart_total").innerHTML='&#8377;'+getsubtotalprice(sida).toFixed(2);
    }*/
    
    
// viewProduct();
// SetData();
}
</script>

<script>
// minus quantity in cart
function minus(ida,sida,p_size_id) {
// quantity update
    var x = parseInt($('#qty_' + sida).attr('qty'));
    var qty_id = parseInt($('#qty_' + sida).attr('qty_id'));
    var a = parseInt($('#qty_' + sida).val());
    var b = parseInt(1);
    var c = parseInt(a - b);
  
        if(c>0){
            
           let storageProducts1 = JSON.parse(localStorage.getItem('products'));
            let products1 = storageProducts1.filter(product1 => product1.productId == sida);
            products1[0].cart_p_qty=c;
            
            let storageProducts = JSON.parse(localStorage.getItem('products'));
            let products = storageProducts.filter(product => product.productId != sida);
            products.push(products1[0]);
            localStorage.setItem('products', JSON.stringify(products));
            
            $('#qty_' + sida).val(parseInt(c));
            
        
            <?php 
            if(basename($_SERVER['PHP_SELF'])=='cart.php' || basename($_SERVER['PHP_SELF'])=='checkout.php'){ ?>
            SetData();
                document.getElementById("cart_total_"+sida).innerHTML=gettotalprice(sida).toFixed(2);
            document.getElementById("sub_total").innerHTML=getsubtotalprice(sida).toFixed(2);
            <?php } ?>
            // document.getElementById("cart_total").innerHTML='&#8377;'+getsubtotalprice(sida).toFixed(2);
            
        
        
        }
        else{
            //  data for quantity update
           var i = localStorage.getItem("cart");
    var i_ = localStorage.getItem("cart_history");
    var product_del_id = Check_cart(i_,ida,p_size_id);
    
    // removing product from localstorage
    let storageProducts = JSON.parse(localStorage.getItem('products'));
    let products = storageProducts.filter(product => product.productId != sida);
    localStorage.setItem('products', JSON.stringify(products));

    // response for site
    $("#hide_A"+sida).hide();
    $("#hide_B"+sida).show();
    // $("#cart_quantity").html(parseInt($("#cart_quantity").html())-1);
    // $("#cart_quantity2").html(parseInt($("#cart_quantity2").html())-1);
    // $("#cart_quantity3").html(parseInt($("#cart_quantity3").html())-1);
    // $("#cartdel_"+sida).remove();
    
    // setting cart qty
    if(i !=0){ localStorage.setItem("cart", i-1); }
    var i2 = localStorage.getItem("cart");
    if(i2 == 0){ localStorage.setItem("cart_history", 0); }
            
          
    }
    
    
           /* <?php 
            if(basename($_SERVER['PHP_SELF'])=='cart.php' || basename($_SERVER['PHP_SELF'])=='checkout.php'){ ?>
            SetData();
                document.getElementById("cart_total_"+sida).innerHTML=gettotalprice(sida).toFixed(2);
            document.getElementById("sub_total").innerHTML=getsubtotalprice(sida).toFixed(2);
            <?php } ?>*/
            // document.getElementById("cart_total").innerHTML='&#8377;'+getsubtotalprice(sida).toFixed(2);



viewProduct();
SetData();
}
</script>

<script>
function removeItem(ida,sida,p_size_id){
            
    var i = localStorage.getItem("cart");
    var i_ = localStorage.getItem("cart_history");
    var product_del_id = Check_cart(i_,ida,p_size_id);
    
    // removing product from localstorage
    let storageProducts = JSON.parse(localStorage.getItem('products'));
    let products = storageProducts.filter(product => product.productId != sida);
    localStorage.setItem('products', JSON.stringify(products));

    // response for site
    $("#hide_A"+sida).hide();
    $("#hide_B"+sida).show();
    // $("#cart_quantity").html(parseInt($("#cart_quantity").html())-1);
    // $("#cart_quantity2").html(parseInt($("#cart_quantity2").html())-1);
    // $("#cart_quantity3").html(parseInt($("#cart_quantity3").html())-1);
    $("#cartdel_"+sida).remove();
    
    // setting cart qty
    if(i !=0){ localStorage.setItem("cart", i-1); }
    var i2 = localStorage.getItem("cart");
    if(i2 == 0){ localStorage.setItem("cart_history", 0); }
    
    <?php 
    if(basename($_SERVER['PHP_SELF'])=='cart.php' || basename($_SERVER['PHP_SELF'])=='checkout.php'){ ?>
    // document.getElementById("cart_total_"+sid).innerHTML=gettotalprice(sid).toFixed(2);
    // document.getElementById("sub_total").innerHTML=getsubtotalprice(sid).toFixed(2);
    <?php } ?>
    // document.getElementById("cart_total").innerHTML='&#8377;'+getsubtotalprice(sid).toFixed(2);

    if(window.location.href == '<?=base_url('checkout');?>'){
       window.location=window.location.href;
    }
    
    viewProduct();
    SetData();
}
</script>

<script>
function Check_product_in_cart(i,id,size_id){
    for(x=0;x<=i;x++){
            if(localStorage.getItem("cart_p_id["+x+"]")==id && localStorage.getItem("cart_size_id["+x+"]")==size_id){
                    return true;
                    break;
            }
        }
        return false;
}
</script>

<script>
function Check_cart(i,id,size_id){
    for(x=0;x<=i;x++){
            if(localStorage.getItem("cart_p_id["+x+"]")==id && localStorage.getItem("cart_size_id["+x+"]")==size_id){
                    return x;
                    break;
            }
        }
}
</script>

<script>
// document.getElementById("to_pays").innerHTML=getsubtotalprice(1).toFixed(2);
</script>

<script>
function getprice(id) {
    let Products_cart = JSON.parse(localStorage.getItem('products'));
    var j = "";
        for (j in Products_cart) {
            if(Products_cart[j].productId == id){
                return Products_cart[j].cart_p_current_price;
            }
            
        }
}
</script>

<script>
function gettotalprice(id) {
    let Products_cart = JSON.parse(localStorage.getItem('products'));
    var j = "";
        for (j in Products_cart) {
            if(Products_cart[j].productId == id){
                return Products_cart[j].cart_p_current_price*Products_cart[j].cart_p_qty;
            }
            
        }
}
</script>

<script>
function getsubtotalprice(id) {
    let Products_cart = JSON.parse(localStorage.getItem('products'));
    var j = "";
    var total = 0;
        for (j in Products_cart) {
            if(Products_cart[j].productId){
                 total += Products_cart[j].cart_p_current_price*Products_cart[j].cart_p_qty;
            }
            
        }
        return total;
}
</script>

<script>
// function checkoutview(){
//  <div class="cart-list-product" id="hidem_1">
//                 <div class="row">
//                   <div class="col-4"><img class="img-fluid" src="assets/uploads/product-featured-12.jpeg" alt="Dhara Ricebran Refined oil "></div>
//                   <div class="col-8">
                       
                   
//               <!--<span class="badge badge-success">50% OFF</span>-->
//               <a class="float-right remove-cart" href="#" onclick="del(1)"><i class="mdi mdi-close"></i></a>
//               <h5><a href="#">Dhara Ricebran Refined oil </a></h5>
//               <h6><strong><span class="mdi mdi-approval"></span> Available in</strong> - 1L</h6>
//               <p class="offer-price mb-0">
//                     <span>₹115.00</span>
//                     <del class="text-black-50 font-weight-normal">₹150.00</del>
//                     <br>
//                     <span class="text-success font-italic">You save ₹35.00</span>
//                     <br>
//                     <span class="text-black-50 font-weight-normal">
//                         QTY : 1                    </span>                             
//               </p>
//               </div>
//               </div>
//             </div>
                
// }
</script>

<script>
<?php if(basename($_SERVER['PHP_SELF'])=='checkout.php'){ ?>
function checkoutview(){
            let Products_cart = JSON.parse(localStorage.getItem('products'));
            var myObj, i, j, x = "";
            sub_total=0;
            var i = 0;
              for (j in Products_cart) {
                if(j !='undefined'){
                    var img = Products_cart[j].image;
                    var p_name = Products_cart[j].cart_p_name;
                    var c_price = Products_cart[j].cart_p_current_price;
                    var o_price = Products_cart[j].cart_p_old_price;
                    var size_id = Products_cart[j].cart_size_id;
                    var size_name = Products_cart[j].cart_size_name
                    var color_id = Products_cart[j].cart_color_id;
                    var color_name = Products_cart[j].cart_color_name;
                    var p_id = Products_cart[j].cart_p_id;
                    var p_name = Products_cart[j].cart_p_name;
                    
                    var primaryid_ct = p_id+''+size_id+''+color_id;
                    
                    var a = ((o_price-c_price)/o_price)*100;
                    var off = a.toFixed();
        
                x += 
                '<div class="cart-items bg-white position-relative border-bottom"  id="cartdel_'+primaryid_ct+'">'
                +''+
                '<b class="position-absolute">'
                +''+
                '<span class="badge badge-secondary m-3">'
                +off+
                '% Off</span>'
                +''+
                '</b>'
                +''+
                '<div class="d-flex  align-items-center p-3">'
                +''+
                '<a href="#"><img src="../assets/uploads/'+img+'" alt="'+p_name+'" class="img-fluid"></a>'
                +''+
                '<div class="ml-3 text-dark text-decoration-none w-100">'
                +''+
                '<h5 class="mb-1">'+p_name+'</h5>'
                +''+ 
                '<p class="mb-2"><span>'+size_name+'</span> &nbsp;&nbsp;&nbsp; <span class="badge" style="background-color: '+color_name+';">'+color_name+'</span></p>'
                +''+
                '<p class="text-muted mb-2">(&#8377;'+(c_price*1).toFixed(2)+')&nbsp;'+size_name+'</p>'
                +''+
                '<div class="d-flex align-items-center">'
                +''+
                '<p class="total_price font-weight-bold m-0"><span>&#8377;</span><span id="cart_total_'
                +primaryid_ct+'">'
                +(c_price*Products_cart[j].cart_p_qty).toFixed(2)+
                '</span></p>'
                +''+
                '<div class="input-group input-spinner ml-auto cart-items-number">'
                +''+
                '<div class="input-group-prepend">'
                +''+
                '<button class="btn btn-success btn-sm" type="button" id="button-plus" onclick="plus('
                +p_id+','+primaryid_ct+
                ')"> + </button>'
                +''+
                '</div>'
                +''+
                '<input type="text" class="form-control" id="qty_'
                +primaryid_ct+
                '" qty="'+primaryid_ct+
                '" readonly value="'+Products_cart[j].cart_p_qty+'">'
                +''+
                '<div class="input-group-append">'
                +''+
                '<button class="btn btn-success btn-sm" type="button" id="button-minus" onclick="minus('
                +p_id+','+primaryid_ct+','+size_id+
                ')"> − </button>'
                +''+
                '</div>'
                +''+
                '</div>'
                +''+
                '</div>'
                +''+
                '</div>'
                +''+
                '</div>'
                +''+
                '</div>';
                  }
              }
            
            document.getElementById("Cart_data").innerHTML=x;
}
checkoutview();
<?php } ?>
</script>

<script>
function getval(id) {
	let Products_cart = JSON.parse(localStorage.getItem('products'));
	var j = "";
	for (j in Products_cart) {
		if (Products_cart[j].productId == id) {
			return true;
		}
	}
	return false;
}
</script>


<script>
function wish_check(id) {
	let wish_list = JSON.parse(localStorage.getItem('wish_list'));
	var j = "";
	for (j in wish_list) {
		if (wish_list[j].productId == id) {
			return true;
		}
	}
	return false;
}
</script>

<script>
function getcartitem(id) {
	let Products_cart = JSON.parse(localStorage.getItem('products'));
	var j = "";
	for (j in Products_cart) {
		if (Products_cart[j].productId == id) {
			return true;
		}
	}
	return false;
}
</script>

<script>
function get_cart_item() {
	let Products_cart = JSON.parse(localStorage.getItem('products'));
	if(Products_cart == null){
	    return 0;
	}
	return Products_cart.length;
}
</script>

<script>
function get_wish_list_item() {
	let wish_list = JSON.parse(localStorage.getItem('wish_list'));
	if(wish_list == null){
	    return 0;
	}
	return wish_list.length;
}
</script>

<script>
function getval2(id) {
	let Products_cart = JSON.parse(localStorage.getItem('products'));
	var j = "";
	for (j in Products_cart) {
		if (Products_cart[j].productId == id) {
			return Products_cart[j].cart_p_qty;
		}

	}
}
</script>


<script>
// All product Default Value
function Myvalueput(idall) {

	var size = idall;
	var size_array = size.split(",");
	var size_id = size_array[0];
	var size_name = size_array[4];
	var p_old_price = size_array[1];
	var p_current_price = size_array[2];
	var p_qty = size_array[3];
	var id = size_array[5];
	var color_id = size_array[6];
	var color_name = size_array[7];
	var sid = id + size_id + color_id;
	$('#price_c_' + id).html(p_current_price);
	$('#p_current_price_' + id).val(p_current_price);
	$('#size_id_' + id).val(size_id);
	$('#size_name_' + id).val(size_name);
	$('#color_id_' + id).val(color_id);
	$('#color_name_' + id).val(color_name);

/*	var pic = size_array[6];
	var pic2 = $('#pic2_' + id).val();

	if (pic == '') {
		$('#pic_' + id).attr('src', 'assets/uploads/' + pic2);
		$('#p_featured_photo_' + id).val(pic2);
	} else {
		$('#pic_' + id).attr('src', 'assets/uploads/' + pic);
		$('#p_featured_photo_' + id).val(pic);
	}*/

	$('#qty_' + id).attr('qty', parseInt(p_qty));
	$('#qty2_' + id).attr('qty', parseInt(p_qty));
	$('#price_o_' + id).html(p_old_price);
	$('#p_old_price_' + id).val(p_old_price);
	var a = ((p_old_price - p_current_price) / p_old_price) * 100;
	var off = a.toFixed();
	$('#offer_' + id).html(off + ' % off');
	// alert(size_id);
	var primaryid = id + size_id + color_id;

        
	$('[id^=wish_hide_A' + id + ']').css('display', 'none');
	$('[id^=hide_A' + id + ']').css('display', 'none');
	$('[id^=hide_B' + id + ']').css('display', 'none');
	
	var x = localStorage.getItem("cart");
	if (x == null) {
		var product_add = false;
		var x = 1;
	} else {
		// checking product in cart
		var product_add, p_qty = '';
		product_add = getval(primaryid);

		// $("#cart_quantity").html(parseInt(localStorage.getItem("cart")));
		// $("#cart_quantity2").html(parseInt(localStorage.getItem("cart")));
		// $("#cart_quantity3").html(parseInt(localStorage.getItem("cart")));


	}

	if (product_add == true) {
		p_qty = getval2(primaryid);
		$('#qty_' + primaryid).val(parseInt(p_qty));
		$('#hide_A' + primaryid).css('display', 'flex');
	} else if (product_add == false) {
		$('#hide_B' + primaryid).css('display', '');
	}
	
	var num = get_wish_list_item();
	if (num == 0 || num == null) {
		var wish_add = false;
		var num = 1;
	} else {
		// checking product in cart
		var wish_add = '';
		wish_add = wish_check(primaryid);
	}

	if (wish_add == true) {
		$('#wish_hide_A' + primaryid).css('display', 'flex');
		$('#wish_hide_A' + primaryid).toggleClass("active");
	} else if (wish_add == false) {
		$('#wish_hide_A' + primaryid).css('display', 'flex');
	}
}
</script>


<script>
    function get_product_stock(p_id,size_id,color_id) {
    	$.ajax({
    		type: "POST",
    		url: "<?=base_url('get/product_stock');?>",
    		data: {
    			p_id: p_id,
    			size_id: size_id,
    			color_id: color_id
    		},
    		success: function(data2) {
    		    console.log(data2);
    		    var obj = JSON.parse(data);
    		    if(obj.log == 1){
    		        return 100;
    		    }
    		    else if(obj.log == 0){
    		        return null;
    		    }
    		}
    	});
    }
</script>


<script>
    function SetData() {
    	var dataString = [];
    	dataString = localStorage.getItem("products");
    	console.log(dataString);
    	$.ajax({
    		type: "POST",
    		url: "<?=base_url('add_to_cart');?>",
    		data: {
    			data: dataString
    		},
    		success: function(data2) {
    		    console.log(data2);
    		}
    	});
    }
    SetData();
</script>

<script>
	// pin code verify
	$('#pin_code').keypress(function(event){
	  if(event.keyCode == 13){
	    pin_verify();
	  }
	});
</script>

<script>	
	function pin_verify(){
	        var pin_code = $("#pin_code").val();
	        $.ajax({
	            type: "POST",
	            url: "<?=base_url('get/pin_code');?>",
	            data: {
	                pin_code: pin_code
	            },
	            success: function(data) {
	               // console.log(data);
	                var obj = JSON.parse(data);
	                // alert(data);
	                if(obj.pin_count == 0){
	                    Swal.fire({
                    	title: "ERROR!",
                    	html: 'Sorry We Can not Provide Delivery services this area.',
                    	type: "error",
                    	showConfirmButton: true,
                    	timer: 5000
                    	});
	                }
	                if(obj.pin_count == 1){
	                    $("#pin_verified").html(obj.pin_code);
	                    $("#pin_verified2").html(obj.pin_code);
	                    Swal.fire({
                    	title: "SUCCESS!",
                    	html: 'Congrats We  Provide Delivery services this area.',
                    	type: "success",
                    	showConfirmButton: true,
                    	timer: 5000
                    	});
	                    window.location=window.location.href;
	                    $('#pin_modal').modal('toggle');
	                }
	            }
	        });
	}
</script>



<script>
    // AJAX call for autocomplete 
$(document).ready(function(){
	$("#search_item").keyup(function(){
	   // console.log($(this).val());
	   
	   var keyword = $(this).val();
	   var id = $('#id').val();
	   var mid = $('#mid').val();
	   var type = $('#type').val();
	   var order = $('#order').val();
	   var page = $('#page').val();

		$.ajax({
		type: "POST",
		url: "<?=base_url('get/product');?>",
		data: {keyword: keyword,id: id,mid: mid, type: type,order: order,page: page},
		success: function(data){
		  //  console.log(data);
			$("#search_result").html(data);
			setup_product();
		}
		});
	});
});

</script>

<script>
    function setup_product() {

	$('[id^=hide_A]').css('display', 'none');
	$('[id^=hide_B]').css('display', 'none');

	var numItems = $('.form_value').length;
	for (i = 0; i < numItems; i++) {

		var id = parseInt($('.form_value').eq(i).attr('id2'));
		var size = $('#size_' + id).val();
		if (size) {

			var size_array = size.split(",");
			var size_id = size_array[0];
			var size_name = size_array[4];
			var p_old_price = size_array[1];
			var p_current_price = size_array[2];
			var p_qty = size_array[3];
			
			var color_id = size_array[6];
			var color_name = size_array[7];
			var primaryid = id + '' + size_id + '' + color_id;
			
			$('#price_c_' + id).html(p_current_price);
			$('#p_current_price_' + id).val(p_current_price);
			$('#size_id_' + id).val(size_id);
			$('#size_name_' + id).val(size_name);
			
			$('#color_id_' + id).val(color_id);
			$('#color_name_' + id).val(color_name);
			
			$('#qty_' + id).attr('qty', parseInt(p_qty));
			$('#qty2_' + id).attr('qty', parseInt(p_qty));
			$('#price_o_' + id).html(p_old_price);
			$('#p_old_price_' + id).val(p_old_price);
			var a = ((p_old_price - p_current_price) / p_old_price) * 100;
			var off = a.toFixed();
			$('#offer_' + id).html(off + ' % off');

			var x = localStorage.getItem("cart");
			if (x == null) {
				var product_add = false;
				var x = 1;
			} else {
				// checking product in cart
				var product_add, p_qty = '';
				product_add = getval(primaryid);

				// $("#cart_quantity").html(parseInt(localStorage.getItem("cart")));
				// $("#cart_quantity2").html(parseInt(localStorage.getItem("cart")));
				// $("#cart_quantity3").html(parseInt(localStorage.getItem("cart")));


			}

			if (product_add == true) {
				p_qty = getval2(primaryid);
				$('#qty_' + primaryid).val(parseInt(p_qty));
				$('#hide_A' + primaryid).css('display', 'flex');
			} else if (product_add == false) {
				$('#hide_B' + primaryid).css('display', 'inline-flex');
			}

		}
	}
}
</script>