<?php

class Cart_Model extends CI_Model {

    var $tablename = 'tbl_cart';

    function getCartDetail() {
        $this->db->where('session_id', $this->session->userdata('my_session_id'));
        $query = $this->db->get($this->tablename);
        $result = $query->row_array();
        return $result;
    }

    function updateCart($cartData) {
        // pr($cartData);die;
        $this->db->set('sub_total', $cartData['sub_total']);
        if ($cartData['location_id'])
            $this->db->set('location_id', $cartData['location_id']);
        if ($cartData['location_name'])
            $this->db->set('location_name', $cartData['location_name']);
        $this->db->set('gst_per', $cartData['gst_per']);
        $this->db->set('pst_per', $cartData['pst_per']);
        $this->db->set('hst_per', $cartData['hst_per']);
        $this->db->set('coupon_id', $cartData['coupon_id']);
        $this->db->set('coupon_code', $cartData['coupon_code']);
        $this->db->set('discount', $cartData['discount']);
        $this->db->set('coupon_percentage', $cartData['coupon_percentage']);
        $this->db->set('gst', $cartData['gst']);
        $this->db->set('pst', $cartData['pst']);
        $this->db->set('hst', $cartData['hst']);
        if($cartData['area_id'])
        $this->db->set('area_id', $cartData['area_id']);
        if ($cartData['area_name'])
        $this->db->set('area_name', $cartData['area_name']);
        if ($cartData['delivery_charges'])
        $this->db->set('delivery_charges', $cartData['delivery_charges']);
        $this->db->set('total_cart_price', $cartData['total_cart_price']);
        if ($cartData['cart_id']) {
            $this->db->where('cart_id', $cartData['cart_id']);
            $this->db->where('session_id', $this->session->userdata('my_session_id'));
            $response = $this->db->update($this->tablename);
        } else {
            $this->db->set('session_id', $this->session->userdata('my_session_id'));
            $response = $this->db->insert($this->tablename);
        }
        return $response;
    }

    function deleteByCartId($cartId) {
        $this->db->where('session_id', $this->session->userdata('my_session_id'));
        $this->db->where('cart_id', $cartId);
        $query = $this->db->delete($this->tablename);
        return $result;
    }
    
      function getTotalCart() {
        $this->db->where('session_id', $this->session->userdata('my_session_id'));
        $query = $this->db->get($this->tablename);
        $result = $query->result_array();
        return $result;
    }   
    

    function emptyCart() {
        $this->db->where('session_id', $this->session->userdata('my_session_id'));
        $query = $this->db->delete($this->tablename);
        return $result;
    }

}