<?php 
if (isset($_POST['addfc_cart'])) {
extract($_POST);
date_default_timezone_set('Asia/Kolkata');
$date = date('Y-m-d H:i:s');
$prod_id= $_POST['prod_id'];
$prd_name= $_POST['prd_name'];
$sql_qrr="select * from product where id='".$prod_id."'";
$res_qrr = mysqli_query($conn, $sql_qrr);
$data_qrr= mysqli_fetch_array($res_qrr);
$prod_quanttity= $_POST['prod_quanttity'];
$sql1="select * from product_detail where id='".$prod_quanttity."'";
$res1 = mysqli_query($conn, $sql1);
$data= mysqli_fetch_array($res1);
$prod_size=$data['prod_quantity'].$data['prod_quantity_type'];
$price=$data['prod_price'];
$prd_details=$data['id'];
$quantity="1";
$user_id=$_SESSION['id'];
$sql="INSERT into addto_cart(prod_details_id,prod_id,user_id,prod_name,prod_size,quantity,price,created_date) values ('$prd_details','$prod_id','$user_id','$prd_name','$prod_size','$quantity','$price','$date')";
//echo $sql; exit();
if(mysqli_query($conn, $sql))
{
header("location:cart.php");
}
} ?>
<section class="product-items-slider section-padding pb-20">
	<div class="container">
		<div class="section-header">
			<h5 class="heading-design-h5">Featured Product <span class="badge badge-primary"></span> 
			</h5>
		</div>
    <form action="" method="POST" action=""> 
		<div class="owl-carousel owl-carousel-featured">
			<?php 
                $sql_fect="select sub_category.sub_category_name,category.cat_name,sub_sub_category.sub_sub_cat_name,product.* from product join category on product.category_id=category.id join sub_category on product.sub_category_id=sub_category.id join sub_sub_category on product.sub_sub_cat_id=sub_sub_category.id where product.feacture_product='1'";
                    $result_fect = mysqli_query($conn, $sql_fect);
                   while($res_fc= mysqli_fetch_array($result_fect)){
                  ?>
			<div class="item">
				 <?php $prd_id=$res_fc['id'];
                $sql_pfc=mysqli_query($conn,"SELECT * from product_detail where prod_id='$prd_id'");
                $res_pfc=mysqli_fetch_array($sql_pfc); ?>
                <?php $cat_name=$res_fc['cat_name']; 
                  $scat_name=$res_fc['sub_category_name']; 
                  $sub_sub_cat_name=$res_fc['sub_sub_cat_name']; 
                  $prod_name=$res_fc['prod_name']; 
                  $category = strtolower(str_replace(" ", "-", $cat_name));
                  $sub_category = strtolower(str_replace(" ", "-", $scat_name));
                  $ssub_category = strtolower(str_replace(" ", "-", $sub_sub_cat_name));
                  $product_name = strtolower(str_replace(" ", "-", $prod_name));?>
				<div class="products-wrapper">     
					<div class="product-image">
						 <form action="https://orangegroceries.com/<?php echo "$category/$sub_category/$ssub_category/$product_name.php"; ?>" method="POST"> 
                                    <input name="id" type="hidden" value="<?php echo $res_fc['id']; ?>" />
                                     <button type="submit" class="dsbtn" style="border:0px;background-color:#fff">
							<img src="admin/product/<?php echo $res_fc['prod_img1'];?>" style="width:100%;" class="img-fluid"></button>
                            </form>
						</form>
					</div>
					<input name="prod_id" id="prod_id" value="<?php echo $res_fc['id']; ?>" class="prd_id" type="hidden">
          <input name="prd_name" id="name" class="name" value="<?php echo $res_fc['prod_name']; ?>" type="hidden">
					<div class="product-other-info">
						<div class="product-name">
							<form action="https://orangegroceries.com/<?php echo "$category/$sub_category/$ssub_category/$product_name.php"; ?>" method="POST"> 
              <input name="id" type="hidden" value="<?php echo $res_fc['id']; ?>" />
               <button type="submit" class="dsbtn" style="border:0px;background-color:#fff"><?php echo $res_fc['prod_name']; ?></button>
              </form>
						</div>
						<div class="product-prize">
							<span class="mrp-txt">mrp</span>
							<span class="main-prize"><strike><i class="fa fa-inr"></i>&nbsp;<span id="prdfhide"><?php echo $res_pfc['prod_cross_price']; ?></span><span id="prodf_cross"></span></strike></span>
							<span class="discounted-prize">
								<i class="fa fa-inr"></i>&nbsp;<span id="prddfhide" class="text-success">  <?php echo $res_pfc['prod_price']; ?></span><span id="prodf_price"></span> </span>
						</div>
						<div class="product-add-to-cart-btn">
							<div class="shop-select-product">
								<select class="form-control" name="prod_quanttity" id="prodf_quanttity" style="width:90%;">
									<?php $prd_id=$res_fc['id'];
                                    $sql2="SELECT * from product_detail where prod_id='$prd_id'";
                                    $exe2=mysqli_query($conn,$sql2);
                                    while ($res2=mysqli_fetch_array($exe2))
                                    {
                                        $id = $res2['id'];
                                      $price =$res2['prod_quantity'].$res2['prod_quantity_type'];
                                       echo "<option value='".$id."'>".$price."</option>";
                                        } ?>
								</select>
							</div>
							
							<?php   if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) { ?>
									 <a href="javascript:void(0);"><button type="submit" name="addfc_cart" id="cartsave" style="border:0px;background-color:#ec3237; color:#fff;float: left;color: #fff;padding: 2px 2px;border-radius: 6px"><i class="mdi mdi-cart-outline" aria-hidden="true"></i> Add To Cart</button></a><?php }else{ ?> 
									 
									 <a href="login.php" > <button type="button" class="" style="border:0px;background-color:#ec3237; color:#fff;float: left;color: #fff;padding: 2px 2px; border-radius: 6px"><i class="mdi mdi-cart-outline"></i> Add To Cart</button></a>
									 
									 <?php } ?>
							 
						</div>
					</div>
					<div class="discount-in-percent"><span id="discfhide"><?php echo $res_pfc['prod_discount']; ?></span><span id="prodf_discount"></span>% off</div>
				</div>
			</div>
		<?php } ?>
  </form>
		</div>
	</div>
</section>
<script type="text/javascript">
$(function() {
    $(document.body).on('change',"#prodf_quanttity",function (e) {
        var qid = $(this).val();
       // alert(qid);
        $.ajax({
            method: "POST",
            url: "ajax_prd_price.php",
            data:'qid='+qid,
            dataType:'JSON',
            success: function(data){
                $('#prodf_price').text(data.prod_price);
                $('#prodf_cross').text(data.prod_cross_price);
                $('#prodf_discount').text(data.prod_discount);
                console.log(data);
            }
        });
    });
});
   $(function(){
$('body').on('change', '#prodf_quanttity', function(){    
//$(document).ready(function(){
   // $('#prod_quanttity').on('change', function() {
      if ( this.value == '0')
      {
        $("#prdfhide").show();
        $("#prddfhide").show();
        $("#discfhide").show();
      }
      else
      {
         $("#prdfhide").hide();
        $("#prddfhide").hide();
        $("#discfhide").hide();
      }
    });
});
    
</script>