

    <div class="offcanvas-overlay"></div>

    <!-- Page Title/Header Start -->
    <div class="page-title-section section" data-bg-image="assets/images/bg/page-title-1.webp">
        <div class="container">
            <div class="row">
                <div class="col">

                    <div class="page-title">
                        <h1 class="title">My Cart</h1>
                        <ul class="breadcrumb">
                            <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>">Home</a></li>
                            <li class="breadcrumb-item active">Cart</li>
                        </ul>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <!-- Page Title/Header End -->
    <?php if($this->session->userdata('customer')){

            $cartitem = $this->db->where('c_id', $this->session->userdata('customer'))->count_all_results('chechout');


        }
        else{

            $cartitem= sizeof($this->cart->contents());
        } ?>

<?php

          $attributes = array('method' => 'post','id' => 'checkout_form');

          echo form_open_multipart('order/checkout/', $attributes);

          ?>
    <!-- Shopping Cart Section Start -->
    <div class="section section-padding">
        <div class="container">
            <form class="cart-form" action="#">
                <table class="cart-wishlist-table table">
                    



                    <thead>
                        <tr>
                            <th class="name" colspan="2">Product</th>
                            <th class="price">Price</th>
                            <th class="quantity">Quantity</th>
                            <th class="subtotal">Total</th>
                            <th class="remove">&nbsp;</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php  

                             $delivery_charge=0;

                            if(!$this->session->userdata('customer')){
                            $grandtotal=0;

                                if(count($this->cart->contents())<1){ ?>

                                <tr>

                                    <td align="center">

                                <p>There are no items in this cart. Please add to cart your favourite product.</p><br>

                                    </td>

                                </tr>

                            <?php }

                            

                        foreach ($this->cart->contents() as $items) {

                                $data_product = $this->db->select('*')->where('prd_id', $items['id'])->get('product')->result_array();

                                // echo $this->db->last_query();

                                $prd_img=explode(",", $data_product[0]['p_img']);
                                $sellprice=$data_product[0]['p_sell_price'];

                                    $total=$sellprice*$items['qty'];

                                    $grandtotal=$grandtotal+$total;

                                    $shipping_charge=$items['qty']*$data_product['0']['shiping_chrg'];
                                $delivery_charge=$delivery_charge+$shipping_charge;
                         ?>
                        <tr>
                            <td class="thumbnail"><a href="#"><img src="<?php echo base_url();?>/uploads/product/<?php echo $data_product[0]['primary_image']; ?>" alt="cart-product-1"></a></td>
                            <td class="name"> <a href="<?php echo base_url().'Product/product_details/'.md5($data_product[0]['prd_id']).'/?mode='.md5($data_product[0]['prd_id']); ?>"><?php echo $data_product[0]['p_title']; ?></a></td>
                            <td class="price"><span>₹<?php echo $data_product[0]['p_sell_price'];?></span></td>
                            <td class="quantity">
                                <div class="product-quantity">
                                    <span class="qty-btn minus qty-minus" data-productid="<?php echo $items['rowid'];?>" data-productqty="<?php echo $items['qty'];?>" data-productprice="<?php echo $data_product[0]['p_sell_price'];?>" ><i class="ti-minus"></i></span>
                                    <input type="text" class="input-qty" id="quantity<?php echo $id; ?>" value="<?php echo $items['qty']; ?>"  name="quantity[]" readonly>
                                    <span class="qty-btn plus qty-plus"  data-productid="<?php echo $items['rowid'];?>" data-productqty="<?php echo $items['qty'];?>" data-productprice="<?php echo $data_product[0]['p_sell_price'];?>"><i class="ti-plus"></i></span>
                                </div>
                            </td>
                            <td class="subtotal"><span>₹<?php echo $total; ?></span></td>
                            <td class="remove"><a href="javascript:void(0)" class="btn del_cart"  data-productid="<?php echo $items['rowid'];?>" >×</a></td>
                        </tr>
                        <?php } } else{

                                if($cartitem<1){

                                    ?>
                                    <tr>

                                    <td align="center">

                                <p>There are no items in this cart. Please add to cart your favourite product.</p><br>

                                    </td>

                                </tr>

                                    <?php

                                }
                                //$delivery_charge=0;
                                $grandtotal=0;

                                $cart_data = $this->db->select('*')->where('c_id', $this->session->userdata('customer'))->get('chechout')->result_array();

                                foreach ($cart_data as $key_cart_data) {

                                    $data_product = $this->db->select('*')->where('prd_id', $key_cart_data['prd_id'])->get('product')->result_array();


                                    $sellprice=$data_product[0]['p_sell_price'];

                                    $total=$sellprice*$key_cart_data['quantity'];

                                    $grandtotal=$grandtotal+$total;
                                    $shipping_charge=$key_cart_data['quantity']*$data_product['0']['shiping_chrg'];
                                $delivery_charge=$delivery_charge+$shipping_charge;

                             ?>
                             <tr>
                            <td class="thumbnail"><a href="#"><img src="<?php echo base_url();?>/uploads/product/<?php echo $data_product[0]['primary_image']; ?>" alt="cart-product-1"></a></td>
                            <td class="name"> <a href="<?php echo base_url().'Product/product_details/'.md5($data_product[0]['prd_id']).'/?mode='.md5($data_product[0]['prd_id']); ?>"><?php echo $data_product[0]['p_title']; ?></a></td>
                            <td class="price"><span>₹<?php echo $data_product[0]['p_sell_price']; ?></span></td>
                            <td class="quantity">
                                <div class="product-quantity">
                                    <span class="qty-btn minus qty-minus"  data-productid="<?php echo $key_cart_data['id'];?>" data-productqty="<?php echo $key_cart_data['quantity'];?>" data-productprice="<?php echo $data_product[0]['p_sell_price'];?>"><i class="ti-minus"></i></span>
                                    <input type="text" class="input-qty" id="quantity<?php echo $id; ?>" value="<?php echo $key_cart_data['quantity']; ?>"  name="quantity[]" readonly>
                                    <span class="qty-btn plus qty-plus"  data-productid="<?php echo $key_cart_data['id'];?>" data-productqty="<?php echo $key_cart_data['quantity'];?>" data-productprice="<?php echo $data_product[0]['p_sell_price'];?>"><i class="ti-plus"></i></span>
                                </div>
                            </td>
                            <td class="subtotal"><span>₹<?php echo $total; ?></span></td>
                            <td class="remove"><a href="javascript:void(0)" class="btn del_cart" data-productid="<?php echo $key_cart_data['id'];?>">×</a></td>
                        </tr>
                        <?php } } ?>
                    </tbody>
                </table>
            
            <?php  

            if($this->session->userdata('customer')){

                 if($cartitem>0){
                 $customer1 = $this->db->where('c_id', $this->session->userdata('customer'))->get('customer')->result_array();
                $pindetails = $this->db->where('pin', $customer1[0]['pin'])->get('active_pin')->result_array();

                if(isset($pindetails) && !empty($pindetails))
                {
                
                 $delevery_charge=$pindetails[0]['delevery_charge'];

                }
                else
                {

                $delevery_charge=0;
                }
                
                ?>
                <?php  
                $total_amount=$grandtotal;
                            if ($grandtotal>1000) {
                                    $delivery_charge=0;
                                }
                                $grandtotal=$grandtotal+$delivery_charge;
                                if ($delivery_charge=='0') {
                                    $delivery_charge='Free';
                                }
                                else
                                {
                                $delivery_charge=$delivery_charge;
                                $total_amount=$delivery_charge+$grandtotal;
                                }
                            ?>
            <div class="cart-totals">
                <h2 class="title">Cart totals</h2>
                <table>
                    <tbody>
                        <tr class="subtotal">
                            <th>Subtotal</th>
                            <td><span class="amount">₹<?php echo $grandtotal; ?></span></td>
                        </tr>
                        <!-- <tr class="subtotal">
                            <th>Discount (10%)</th>
                            <td><span class="amount">₹10.00</span></td>
                        </tr> -->
                        <tr class="subtotal">
                            <th>Delivery</th>
                            <td><span class="amount">₹<?php echo $delivery_charge; ?></span></td>
                        </tr>

                        <tr class="total">
                            <th>Total</th>
                            <td><strong><span class="amount">₹<?php echo $total_amount; ?></span></strong></td>
                        </tr>
                    </tbody>
                </table>
                <a href="<?php echo base_url(); ?>order/checkout/" class="btn btn-dark btn-outline-hover-dark">Proceed to checkout</a>
            </div>

            <?php

             } }

            else{

                if(count($this->cart->contents())>0){

            ?>

            <div class="cart-totals">
                <h2 class="title">Cart totals</h2>
                <table>
                    <tbody>
                        <tr class="subtotal">
                            <th>Subtotal</th>
                            <td><span class="amount">₹<?php echo $grandtotal; ?></span></td>
                        </tr>
                        <!-- <tr class="subtotal">
                            <th>Discount (10%)</th>
                            <td><span class="amount">₹10.00</span></td>
                        </tr> -->
                        <tr class="subtotal">
                            <th>Delivery</th>
                            <td><span class="amount">₹<?php echo $delivery_charge; ?></span></td>
                        </tr>
                        <tr class="total">
                            <th>Total</th>
                            <td><strong><span class="amount">₹<?php echo $total_amount; ?></span></strong></td>
                        </tr>
                    </tbody>
                </table>
                <a href="javascript:void(0)" data-toggle="modal" data-target="#myModal" id="moD1" class="btn btn-dark btn-outline-hover-dark">Login For Checkout</a>
            </div>

            <?php } } ?>

            <?php echo form_close(); ?>




        </div>

    </div>
    <!-- Shopping Cart Section End -->
    <script type="text/javascript">

    $(document).ready(function(){

        $('.del_cart').click(function(){

            var del    = $(this).data("productid");

            $.ajax({

                url : "<?php echo base_url(); ?>product/cart_remove",

                method : "POST",

                data : {del: del},

                success: function(data){

                    location.reload();

                }

            });

        });

    });

</script>

<script type="text/javascript">

     $(document).ready(function(){

        $('.qty-plus').click(function(){

            var prdid    = $(this).data("productid");

            var tot1  = $(this).data("productqty")+1;

            var price = $(this).data("productprice")*tot1;

         // $("#totle"+id).val(ttotal);

          $.ajax({

        type: "POST",

        url: "<?php echo base_url(); ?>product/qty_plus",

        data: {prdid : prdid, tot1 : tot1, price : price}, 

        success: function(html) {

         location.reload();

            }

        });

        });

        });

     $(document).ready(function(){

        $('.qty-minus').click(function(){

            var prdid    = $(this).data("productid");

            var tot1  = $(this).data("productqty")-1;

         // $("#totle"+id).val(ttotal);

          $.ajax({

        type: "POST",

        url: "<?php echo base_url(); ?>product/qty_minus",

        data: {prdid : prdid, tot1 : tot1}, 

        success: function(html) {

         location.reload();

            }

        });

        });

        });

   </script>
