Welcome Guest, Not a member yet? Register   Sign In
cart library sometimes works, sometimes not
#1

[eluser]penta997[/eluser]
Hello. I'm using a cart library to get orders in my web bookstore. But when I call a addCart function on one of my book it's works, but not all the time. Please, help

There is my model function:
Code:
function get_books_by_ID($id)
        {
            $this->db->where('BOOK_ID', $id);

            $query =  $this->db->get('books');
            return $query;
            echo vardump($query);
        }


Controller function:
Code:
function addCards()
       {
          
           $id = $this->uri->segment(3);

           $query = $this->Kategorie_model->get_books_by_ID($id);
          
           if($query->num_rows() > 0)
           {
                foreach($query->result() as $item)
                {
                    $data = array(
                    'id'      => $item->BOOK_ID,
                    'qty'     => 1,
                    'price'   => $item->BOOK_Price,
                    'name'    => $item->BOOK_Title

                    );
                    $this->cart->insert($data);
                    
                  
                }

           }

            
       }

And part of view
Code:
<tr>
        <td class="color"><b>Cena: </b>&lt;?php echo $data->BOOK_Price;?&gt;zł</td><td class="border" id="koszyk" >&lt;?php echo anchor('ksiegarnia/addCards/'.$data->BOOK_ID.'/', 'Koszyk'); ?&gt;</td>
    </tr>
     <tr>

and index view, where I displaing a cart total and total_items
Code:
<tr>
                    <td>&lt;?php echo $this->cart->total().'zł';?&gt;</td><td>&lt;?php echo $this->cart->total_items();?&gt;</td>
                </tr>
#2

[eluser]cideveloper[/eluser]
Couple of things

1) I assume there is only one book per BOOK_ID so you shouldn't need to do the loop
2) you don't need the first line in addCards function

Code:
function addCards($id=1){
    $query = $this->Kategorie_model->get_books_by_ID($id);
    if($query->num_rows() > 0){
        $item = $query->row();
        $data = array(
            'id'      => $item->BOOK_ID,
            'qty'     => 1,
            'price'   => $item->BOOK_Price,
            'name'    => $item->BOOK_Title
        );
        $this->cart->insert($data);
    }
}

view

Code:
<tr>
        <td class="color"><b>Cena: </b>&lt;?php echo $data->BOOK_Price;?&gt;zł</td><td class="border" id="koszyk" >&lt;?php echo anchor('ksiegarnia/addCards/'.$data->BOOK_ID, 'Koszyk'); ?&gt;</td>
    </tr>
     <tr>

3) what is the datatype for the user_data field in the ci_sessions table where session data is stored.
#3

[eluser]penta997[/eluser]
Where can i find this info about ci sessions table?
#4

[eluser]cideveloper[/eluser]
However you created the database. e.g. phpmyadmin, etc
#5

[eluser]penta997[/eluser]
BOOK_ID int(10), BOOK_Title varchar(98), BOOK_Price decimal(5,2), but it is a data which I displaing, but temporary I don't save data nowhere.
I will sav data in Order table, later when user check items and accept his address and ect.
#6

[eluser]penta997[/eluser]
the carts still works random. do you have any idea why?? Maybe is something wrong with sesstion configuration or cart configuration??




Theme © iAndrew 2016 - Forum software by © MyBB