<?php
$this->load->view('top');
$adminRes = get_site_email();
date_default_timezone_set('Asia/Kolkata');
$time = date('H:i');
$mediaRes = $media_res;
$overall_rating_product = product_overall_rating($res['products_id'], 'product');
//print_r($res);
$cat_res = get_db_single_row('wps_categories', '*', " category_id='$res[category_id]'");
$sz = explode(',', $res['size_ids']);
$cl = explode(',', $res['color_ids']);
$cart_array = $this->cart->contents();
$insert_flag = 0;
?>
<link href="<?php echo theme_url(); ?>css/magiczoomplus.css" rel="stylesheet" type="text/css" />
<link href="<?php echo theme_url(); ?>css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<div class="page_breadcrumbs">
  <div class="container">
    <ul>
      <li><a href="<?php echo site_url(); ?>">Home</a></li>
      <?php echo category_breadcrumbs($res['category_id']); ?>
      <li><?php echo $res['product_name']; ?></li>
    </ul>
  </div>
</div>
    <section class="product_listing">
        <div class="container">
            <div class="row">
                <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-4 col-sm-6 col-12 details_sidebar">
                    <div class="theiaStickySidebar">
                        <div class="app-figure" id="zoom-fig">
                            <div class="details_zoom">
                                <div class="row">
                                    <div
                                        class="col-xxl-2 col-xl-2 col-lg-2 col-md-2 col-sm-12 col-12 order-xxl-first order-xl-first order-lg-first order-md-first order-last">
             <?php
                  if (is_array($mediaRes) && !empty($mediaRes)) {
                    ?>
                                        <div class="selectors">
            
                                        <?php
                      foreach ($mediaRes as $mres) {
                        ?>
                        <a data-zoom-id="Zoom-1" href="<?php echo get_image('products', $mres['media'], '', '', 'R'); ?>" data-image="<?php echo get_image('products', $mres['media'], '475', '600', 'R'); ?>" title="<?= $res['product_name']; ?>">
                          <img srcset="<?php echo get_image('products', $mres['media'], '80', '100', 'R'); ?>" src="<?php echo get_image('products', $mres['media'], '80', '100', 'R'); ?>" title="<?= $res['product_name']; ?>" alt="<?= $res['product_name']; ?>" class="w-100"/>
                        </a>
                        <?php
                      }
                      ?>         
                                        </div>
                                            <?php
                  }
                  ?>
                                    </div>

                                      <div class="col-xxl-10 col-xl-10 col-lg-10 col-md-10 col-sm-12 col-12">
                                       <a id="Zoom-1" class="MagicZoom" title="<?= $res['product_name']; ?>" href="<?php echo get_image('products', $res['media'], '1000', '1000', 'R'); ?>" data-options="zoomWidth:470; zoomHeight:470px">
                    <img src="<?php echo get_image('products', $res['media'], '475', '600', 'R'); ?>" alt="<?= $res['product_name']; ?>" title="<?= $res['product_name']; ?>" />
                  </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-8 col-sm-6 col-12">
                    <div class="product_details">
                        <form name="details" action="<?php echo site_url(); ?>cart/add_to_cart" method="post">
                            <h1><?php echo $res['product_name']; ?></h1>
                            <div class="styles"><strong>STYLE #</strong><?php echo $res['product_code'];?></div>
                            <div class="product_review">
                                				<?php 
								$reviewsArray = $this->db->query("SELECT * FROM  wps_review WHERE entity_id='" . $res['products_id'] . "'")->result_array();
								if ($reviewsArray>0) {
									foreach ($reviewsArray as $ratingvalue) {
										$rating[] = $ratingvalue['ads_rating'];
									   $average = array_sum($rating)/count($rating);
									}									
								}
								if(!empty($average)){
									$average = $average;
								}else{
									$average = 0;
								}
								?>
                                <div class="rating">
                                    <?php
                                   $ads_rating = $average;
                                    for ($i=1;$i<6;$i++) {
										      ?>
                                      <?php if($i<=$ads_rating){?>
                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                                        viewBox="0 0 16 16">
                                        <path
                                            d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" />
                                    </svg>
                                    <?php } else{ ?>
                                    	<i class="fa fa-star-o"></i>
										  <?php } } ?>
                                      <?php echo form_error('ads_rating');?>
                                </div>
                                	<?php 
									if ($this->session->userdata('user_id') > 0) { ?>
										<a href="<?php echo site_url(); ?>members/post_review/<?php echo $res['products_id']; ?>" class="rating_count">Write Review</a>
										<?php
									}else{?>
										<a href="<?=base_url('login');?>" class="rating_count">Write Review</a>
									<?php } ?>
                               
                            </div>
                            <div class="clearfix"></div>
                            <div class="pro-price-cart details_price">
                                <div class="pro-home-price"> 
                          <span class="product_price"> <?php if($res['category_id']==2){ echo display_price($res['product_price']);} else { echo display_price_india($res['product_price']);} ?></span>
                                </div>
                            </div>

                            <div class="product_size_wrapper">
                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                                    viewBox="0 0 16 16">
                                    <path
                                        d="M0 3.5A1.5 1.5 0 0 1 1.5 2h9A1.5 1.5 0 0 1 12 3.5V5h1.02a1.5 1.5 0 0 1 1.17.563l1.481 1.85a1.5 1.5 0 0 1 .329.938V10.5a1.5 1.5 0 0 1-1.5 1.5H14a2 2 0 1 1-4 0H5a2 2 0 1 1-3.998-.085A1.5 1.5 0 0 1 0 10.5v-7zm1.294 7.456A1.999 1.999 0 0 1 4.732 11h5.536a2.01 2.01 0 0 1 .732-.732V3.5a.5.5 0 0 0-.5-.5h-9a.5.5 0 0 0-.5.5v7a.5.5 0 0 0 .294.456zM12 10a2 2 0 0 1 1.732 1h.768a.5.5 0 0 0 .5-.5V8.35a.5.5 0 0 0-.11-.312l-1.48-1.85A.5.5 0 0 0 13.02 6H12v4zm-9 1a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm9 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2z">
                                    </path>
                                </svg>
                                <div>
                                    <h2>Shipping Worldwide</h2>
                                    <?php if($res['category_id']!=2){
                                      echo "<p> Free Shipping Within India Only</p>";
                                    } ?>
                                </div>
                            </div>
	                       
                            <?php if($res['product_qty']>0){ ?>
                            
                            <div class="details_qty">
                                <button class="minus" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="16"
                                        height="16" fill="currentColor" viewBox="0 0 16 16">
                                        <path d="M4 8a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7A.5.5 0 0 1 4 8z" />
                                    </svg></button>
                                <input type="text" name="qty" id="qty" value="1" class="qty" maxlength="10">
                                <button class="plus" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="16"
                                        height="16" fill="currentColor" viewBox="0 0 16 16">
                                        <path
                                            d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z" />
                                    </svg></button>
                            </div>

	                        <?php } ?>

                            <div class="clearfix"></div>
                              <?php if ($this->session->userdata('user_id') > 0) { ?>
                             <a href="<?php echo site_url('cart/add_to_wishlist/' . $res['products_id']); ?>" class="wishlist_btn" title="Wishlist"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                    fill="currentColor" viewBox="0 0 16 16">
                                    <path
                                        d="m8 2.748-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z">
                                    </path>
                                </svg></a>
                                      <?php } else { ?>
                                          <a href="javascript:void();" onclick="whishlist()" class="wishlist_btn" title="Wishlist"><svg
                                              xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                              fill="currentColor" viewBox="0 0 16 16">
                                              <path
                                                d="M8 2.748l-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z">
                                              </path>
                                            </svg>
                                          </a> 

                                          <script>
                                            function whishlist() {
                                              swal({
                                                title: "Please login to add the product in your wishlist!",
                                                text: "",
                                                type: "warning",
                                                showCancelButton: true,
                                                closeOnConfirm: false,
                                                showLoaderOnConfirm: true,
                                                confirmButtonText: 'Click to Login',
                                                confirmButtonColor: '#ff0000',
                                              }, function (isConfirm) {
                                                if (isConfirm) {
                                                  window.location.href = "<?php echo base_url('login'); ?>";
                                                } else {
                                                  // window.location.href="<?php echo base_url('cart'); ?>";
                                                  //swal("Cancelled", "Your imaginary file is safe :)", "error");
                                                }
                                              });
                                            }
                                          </script>
                                        <?php } ?>
                                <?php if($insert_flag=='1'){ ?>
                            <button class="add_to_button hover_btn" onclick="window.location.href='<?php echo base_url('cart'); ?>'"><svg xmlns="http://www.w3.org/2000/svg" width="16"
                                    height="16" fill="currentColor" viewBox="0 0 16 16">
                                    <path
                                        d="M9 5.5a.5.5 0 0 0-1 0V7H6.5a.5.5 0 0 0 0 1H8v1.5a.5.5 0 0 0 1 0V8h1.5a.5.5 0 0 0 0-1H9V5.5z" />
                                    <path
                                        d="M.5 1a.5.5 0 0 0 0 1h1.11l.401 1.607 1.498 7.985A.5.5 0 0 0 4 12h1a2 2 0 1 0 0 4 2 2 0 0 0 0-4h7a2 2 0 1 0 0 4 2 2 0 0 0 0-4h1a.5.5 0 0 0 .491-.408l1.5-8A.5.5 0 0 0 14.5 3H2.89l-.405-1.621A.5.5 0 0 0 2 1H.5zm3.915 10L3.102 4h10.796l-1.313 7h-8.17zM6 14a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm7 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0z" />
                                </svg> Go to Cart</button>
                            <?php }else{ ?>
                <input type="hidden" name="product_id" value="<?php echo $res['products_id']; ?>" />
                <input type="hidden" name="stockValue" id="stockValue" class="stockValue" value="<?php echo $res['product_qty']; ?>" /> 
                <input type="hidden" name="discount_id" id="discount_id" value="0" />
                <input type="hidden" name="special_offer_id" value="0" />
                <input type="hidden" name="color_id" id="color_id" value="" />
                <input type="hidden" name="size_id" id="size_id" value="" />
                <input type="hidden" name="style_id" id="style_id" value="" />
                <?php if($res['product_qty']>0){ ?>
                <button class="add_to_button hover_btn"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 16 16"><path d="M0 2.5A.5.5 0 0 1 .5 2H2a.5.5 0 0 1 .485.379L2.89 4H14.5a.5.5 0 0 1 .485.621l-1.5 6A.5.5 0 0 1 13 11H4a.5.5 0 0 1-.485-.379L1.61 3H.5a.5.5 0 0 1-.5-.5zM3.14 5l1.25 5h8.22l1.25-5H3.14zM5 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0zm9-1a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0z"></path></svg> <?php if($res['category_id']==2){ echo "Add to cart"; } else { echo "Buy Now";} ?></button> 
                <?php } ?>
              <?php } ?>   
                            <button type="submit" data-id="<?php echo $res['products_id']; ?>" class="add_to_button sendq"><svg xmlns="http://www.w3.org/2000/svg" width="16"
                                    height="16" fill="currentColor" viewBox="0 0 16 16">
                                    <path
                                        d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V4Zm2-1a1 1 0 0 0-1 1v.217l7 4.2 7-4.2V4a1 1 0 0 0-1-1H2Zm13 2.383-4.708 2.825L15 11.105V5.383Zm-.034 6.876-5.64-3.471L8 9.583l-1.326-.795-5.64 3.47A1 1 0 0 0 2 13h12a1 1 0 0 0 .966-.741ZM1 11.105l4.708-2.897L1 5.383v5.722Z" />
                                </svg> Send Enquiry</button>



                        </form>


                        <div class="faqaccodian">
                            <div class="accordion-holder" id="accordion03">
                                <div class="card">
                                    <div class="card-heading"><a class="card-link collapse" data-hover=""
                                            data-bs-toggle="collapse" role="button" aria-expanded="false"
                                            aria-controls="collapse01-1" href="#collapse01-1">Product Details</a></div>
                                    <div class="collapse show" id="collapse01-1" data-bs-parent="#accordion03">
                                        <div class="card-body">
                                           <?php echo html_entity_decode($res['products_description']);?> 
                                            <?php if($res['category_id']!=2){
                                      echo "Note : Delivery in 2-5 Working days
                                      (Delivery time may vary on shipping address)"; 
                                    } else {
                                      echo "Note : Delivery in 4-7 Working days
                                      (Delivery time may vary on shipping address)";
                                    } ?>
                                        </div>
                                    </div>
                                    <div class="card">
                                        <div class="card-heading"><a class="card-link collapsed " data-hover=""
                                                data-bs-toggle="collapse" role="button" aria-expanded="false"
                                                aria-controls="collapse01-3" href="#collapse01-3">Ratings & Reviews</a>
                                        </div>
                                        <div class="collapse" id="collapse01-3" data-bs-parent="#accordion03">
                                            <div class="card-body"> 
                                              <div class="review-style">
                                                  <h3>Review this product</h3>
                                                  <p>Share your thoughts with other customers</p>
                                                      <?php if($this->session->userdata('user_id')>0){ ?>
                                            <a href="<?=base_url('myreview');?>"
                                                class="product_rate">Write Review</a>
                                            <?php } else  { ?>
                                             <a href="<?=base_url();?>login"
                                                class="product_rate">Write Review</a>
                                            <?php } ?>
                                              </div>
                                 <?php if($reviewsArray>0) { 
                                                	foreach ($reviewsArray as $ratingvalue) {
                                        $starArray = $this->config->item('starArray');
                                        krsort($starArray);
										$rating[] = $ratingvalue['ads_rating'];
									   $average = array_sum($rating)/count($rating);
                                         ?>               
                                         <div class="review">
                        <div class="review-title">
        <span class="summary"><i class="fa fa-user"></i> <span><?=$ratingvalue['author']?></span></span>
        <span class="date"><i class="fa fa-calendar"></i><span><?=date('d M Y H:i A', strtotime($ratingvalue['review_date']));?></span></span>
                        </div>
                        <div class="product_ratings">
                        <?php
                              $ads_rating = $ratingvalue['ads_rating'];
                              for ($i = 1; $i < 6; $i++) {
                                ?>
                           <span class="fa fa-star <?php if($i <= $ads_rating) { echo "checked";}?>"></span>
                         <?php } ?>
                        </div>
                        <div class="text"><?=$ratingvalue['text']?></div>
                        <div class="">
<img src="<?php echo get_image('reviews', $ratingvalue['upload_image'], '125', '125', 'R'); ?>" id="pic1" class="profile_picture" width="125" height="125"  />                       
                        </div>
                     </div>                    
                                     <?php                   
									}	 }
                                                ?>               
                                                
                    
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="new_arrvals">
        <div class="container">
     
<?php
if (is_array($related) && !empty($related)) {
  ?>
               <div class="section-title style-2">
                            <h3>Related Products</h3>
                        </div>
             
            <div class="clearfix"></div>
            <div class="owl-carousel product-carousel related-carousal owl-theme">
                      <?php
        foreach ($related as $key => $val) {
          $productImage = get_db_field_value("wps_products_media", "media", "WHERE products_id = '" . $val['products_id'] . "' ORDER BY id asc LIMIT 0, 1");
          ?>
                <!-- item -->
                <div class="item">
                    <!--end product card-->
                    <div class="product-content-wrap">
                        <div class="product-content-img">
                           <a href="<?= base_url($val['friendly_url']); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
                               <img src="<?php echo get_image('products', $val['media'], 270, 370, 'R'); ?>" alt="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>"> 
                            </a>
                        </div>
                        <div class="product-content-details">
                            <h4 class="product-title"><a href="<?= base_url($val['friendly_url']); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>"><?php echo substr($val['product_name'],0,50); ?>..
                                </a></h4>
                            <div class="product-content-bottom">
                            <div class="product-price">
                                                <span> <?php if($val['category_id']==2){ echo display_price($val['product_price']);} else { echo display_price_india($val['product_price']);} ?></span>
                                            </div>
                                
                                <div class="add-cart">
                                    <a class="add" href="<?= base_url($val['friendly_url']); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
                                        <img src="assets/img/icons/cart-icon.svg">
                                        Add to cart
                                    </a>
                                </div>
                            </div>


                        </div>
                    </div>

                    <!--end product card-->
                </div>
                <!-- /item -->
<?php } ?>
            </div>
<?php } ?>

        </div>
    </section>

<div class="clearfix"></div>
<div class="modal fade" id="productID" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="modal-title">Send Enquiry</div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-hidden="true"></button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-7 col-md-7">
                            <div class="product_popup">
                                <div class="product_popup_image">
                                   <img id="pro_img" src="<?=theme_url();?>images/products/Round-Brilliant-Diamond.jpg"  />
                                </div>
                                <div id="pro_name"></div>
                            </div>
                        </div>
                        <div class="col-lg-5 col-md-5">
                            <p id="response"> </p>
                            <form role="form" name="pro-contact-form"  id="pro-contact-form" method="post">
                                <div class="form-group">
                                    <label class="input_label">
                                            <input type="hidden" name="product_id" id="pro_id" > 
                                            <input type="hidden" name="product_name" id="p_name" > 
                                        <input class="form_input" type="text" name="first_name" id="first_name" placeholder="Full Name *" value=""
                                            required="">
                                    </label>
                                </div>


                                <div class="form-group">
                                    <label class="input_label">
                                        <input class="form_input" type="email" name="email" id="email" placeholder="Email ID *"
                                            value="" required="">
                                    </label>
                                </div>


                                <div class="form-group">
                                    <label class="input_label">
                                        <input class="form_input" type="text" name="phone" placeholder="Phone No *"
                                            value="" minlength="10" maxlength="15" required="">
                                    </label>
                                </div>

                                <div class="form-group">
                                    <label class="input_label">
                                        <input class="form_input" type="text" name="location" placeholder="Location *"
                                            value="" required="">
                                    </label>
                                </div>


                                <div class="form-group">
                                    <label class="input_label">
                                        <textarea class="form_input" name="message" placeholder="Message *"
                                            required></textarea>
                                    </label>
                                </div>


                                <div class="form-group">
                                    <button class="contact_btn" type="submit" name="proquery" id="proquery" value="Submit"
                                        data-submit="...Sending">Submit</button>
                                </div>
                            </form>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $this->load->view("bottom"); ?>

 <script>
var dqty = jQuery(".super-attribute-select").find("option:selected").attr("qty");
    var MAX_QTY = 10;
    var MIN_QTY = 1;
    jQuery(".super-attribute-select").change(function() {
        dqty = jQuery(".super-attribute-select").find("option:selected").attr("qty");
        if (typeof dqty == "undefined") {
            MAX_QTY = 10
        } else {
            MAX_QTY = dqty
        }
        jQuery("#qty").val(1)
    });
    jQuery(".plus").click(function() {
        if (typeof MAX_QTY == "undefined") {
            MAX_QTY = 10
        }
        var a = parseInt(jQuery(this).prev(".qty").val());
        if (!a || a == "" || a == "NaN") {
            a = 0
        }
        if (a < MAX_QTY) {
            jQuery(this).prev(".qty").val(a + 1)
        }
    });
    jQuery(".minus").click(function() {
        var a = parseInt(jQuery(this).next(".qty").val());
        if (a == "NaN") {
            a = 0
        }
        if (a > MIN_QTY) {
            jQuery(this).next(".qty").val(a - 1)
        }
    });

     jQuery('.details_sidebar').theiaStickySidebar({
        additionalMarginTop: 90
    });
    </script>

    
<script type="text/javascript">
  setTimeout(function () {
    $('.colorList').eq(0).trigger('click');
    $('.sizeList').eq(0).trigger('click');
    $('.styleList').eq(0).trigger('click');
  }, 600);
    
    $('.styleList').click(function () {
    if ($(this).hasClass("styleList")) {
      $('.styleList').parent('li').removeClass('active');
      $(this).parent('li').addClass('active');
      $('#style_id').val($(this).attr('data-Val'));
      $('.styleArea').html('Style : ' + $(this).attr('data-name'));
    }
   });

  $('.sizeList, .colorList').click(function () {
    if ($(this).hasClass("sizeList")) {
      $('.sizeList').parent('li').removeClass('active');
      $(this).parent('li').addClass('active');
      $('#size_id').val($(this).attr('data-Val'));
      $('.sizeArea').html('Quantity : ' + $(this).attr('data-name'));
    } else {
      $('.colorList').parent('li').removeClass('active');
      $(this).parent('li').addClass('active');
      $('#color_id').val($(this).attr('data-Val'));
      $('.colorArea').html('Color : ' + $(this).attr('data-name'));
    }
    //get value
    var sz = $('#size_id').val();
    var cl = $('#color_id').val();
    if (sz > 0) {
    $.post('<?php echo site_url(); ?>products/get_product_price', {sid: sz, cid: cl, pid: '<?php echo $res['products_id']; ?>'}, function (msg) {
      if (msg) {
         var display_price = '$';
        var txt = msg.split('-');
        if (txt[2] > 0 && txt[0] > 0) {
          var percent = ((txt[1] - txt[2]) * 100) / txt[1];
          $('#price').html('');
          $('#price').html('<span class="product_price"> '+ display_price + txt[2] + ' </span><span class="product_del"> ' + display_price + txt[1] + '</span><span class="discount_value">' + Math.round(percent) + '% Off</span>');
          $('.stock').html('In Stock');
          $('.cartButton').show(0);
          $('.stockValue').val(txt[0]);
          
         
        } else if (txt[1] > 0 && txt[0] > 0) {
          $('#price').html('<i class="fa fa-inr"></i> ' + txt[1]);
          $('.stock').html('In Stock');
          $('.cartButton').show(0);
          $('.stockValue').val(txt[0]);
        } else {
          $('#price').html('OUT OF STOCK');
          $('.stock').html('Out of Stock');
          $('.cartButton').hide(0);
          $('.stockValue').val('0');
        }
      } else {
         $('#price').html('OUT OF STOCK');
         $('.stock').html('Out of Stock');
         $('.stockValue').val('0');
         $('.cartButton').hide(0);
      }

    });
     }
  });
<?php
if ($res['size_ids'] != '' || $res['color_ids'] != '') {
  ?>
    $('.cartButton').click(function (e) {
      if (isEmpty()) {
        e.preventDefault();
        return;
      }
      if ($('#size_id').val() == '' || $('#color_id').val() == '') {
        alert('please select size & color to add in the cart!');
        return false;
      } else {
        $('#cart_form').submit();
      }
    });
  <?php
} else {
  ?>
    $('.cartButton').click(function () {
      if (isEmpty()) {
        e.preventDefault();
        return;
      }
      $('#cart_form').submit();
    });
  <?php
}
?>

</script>


<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

<script type="text/javascript">
  $(document).ready(function () {
<?php
if ($this->session->flashdata('success') != '') {
  ?>
      swal({
        title: "<?php echo $this->session->flashdata('success'); ?>",
        text: "",
        type: "success",
        showCancelButton: true,
        cancelButtonText: "Continue Shopping",
        cancelButtonColor: '#01a1e3',
        confirmButtonColor: '#ff0000',
        confirmButtonText: 'Go to Cart',
        //closeOnConfirm: false,
        //closeOnCancel: false
      }, function (isConfirm) {
        if (isConfirm) {
          window.location.href = "<?php echo base_url('cart'); ?>";
        } else {
          // window.location.href="<?php echo base_url('cart'); ?>";
          //swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
      });
  <?php
}
?>  

      
  });
</script>
<script type="text/javascript">
    $(function() {
   <?php if ($this->session->flashdata('reviewstatus') != '') { ?>
       swal({
            title:"<?php echo $this->session->flashdata('reviewstatus'); ?>",
            confirmButtonColor: '#dc3545',
           });
   <?php } ?>
   });
</script>
<script type="text/javascript" language="javascript">
    $(document).ready(function() {
    $('.sendq').click(function(e) {
        e.preventDefault();
        var pid = $(this).attr("data-id");
        $.ajax({
            url: "<?=base_url();?>products/getproduct",
            data:{pid:pid},
            type: "POST",
            dataType: "json",
            success: function(data) {
                $("#productID").modal('show');
                $("#pro_name").html(data.post.product_name);
                $("#pro_id").val(data.post.products_id);
                $("#p_name").val(data.post.product_name); 
                if(data.post.media!=null) 
                {
                $("#pro_img").attr('src', '<?=base_url()?>uploaded-files/product/'+data.post.media);
                } 
                else{
                    $("#pro_img").attr('src', '<?=theme_url()?>images/products/default.jpg');
                }    
            }

        });

    });
});

$(document).ready(function() {
    $('#proquery').click(function(e) {
        e.preventDefault();
        $(':input[type="submit"]').prop('disabled', true);
            $.ajax({
            url: "<?=base_url();?>products/enquireNow",
            data:$('#pro-contact-form').serialize(),
            type: "POST",
            success: function(data) {
                if (data == 'success') {
               $("#response").html('<div class="alert alert-success alert-dismissible fade show" role="alert">Thank you!! Your Enquiry has been Submitted, our team will contact you soon.<button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
               $('#pro-contact-form').trigger('reset');
               $(':input[type="submit"]').prop('disabled', false);
            }
            else
        {
              $('#response').html('<div class="alert alert-danger alert-dismissible fade show" role="alert">All fields Required !<button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
              $(':input[type="submit"]').prop('disabled', false);
        }
            }
       
        });  
    });
});
</script>