开发者

Code Igniter - carts library random works

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:

function get_books_by_ID($id)
{
    $this->db->where('BOOK_ID', $id);

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

Controller:

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:

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

UPDATE:

vardump is nothing necessary. I want to use var_dump. But the problem is related with adding items to the session with carts library. I have a bookstore, and when I call a addCarts function, sometimes items is added to Carts, and cart function total() and total_items displaying it, but sometimes when I call function, nothing is ha开发者_运维技巧ppened. The items not add into carts. I don't now why this thing have a place. Why the carts library works randomly?


I just ran into this issue and it seems that in the codeigniter cart library the insert function checks the product(s) id and name against a regex only allow alpha-numeric, dashes, underscores and periods

Adjust the regex to what may come up:

$this->cart->product_id_rules = '.a-z0-9_';

$this->cart->product_name_rules = '.\:-_ a-z0-9';

In my case it would randomly add thing to carts too. If you turn on logging and check you'll be able to see that the name or id may contain invalid chars


i am doing as you did, and like you said, the cart is randomly works, it seems can only contain 3 product in cart when i add another product, the product i added wont get into cart..

i am so hopeless, i get mind to change cart libraries with 3rd party

it is because i did not setting session to save to database, like in the tutorial (cart & session) the cart need session to write to database in order to work.

when i set session write to database, the problem solved

you can try...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜