Welcome Guest, Not a member yet? Register   Sign In
Unable to add more than 10 items to cart

I'm testing adding items to the shopping cart like this:

$item = $this->model->getSingleItem();

for($i = 0; $i < 11; $i++) {
            'id' => $item->id++,
            'qty' => 1,
            'price' => 1,
            'name' => $item->title

However, the above loop only adds 10 items to the shopping cart. Even if I modify the loop above to run 20 times, I still get only 10 items in the cart. Is this a known bug, or am I doing something wrong?


echo count($this->cart->contents());

always shows a count of 10 or less. Never more.

I'm using CI 2.1.2. If someone can confirm they don't face this issue in a previous version, perhaps I can use the cart class from an older version of CI.

If it were me, I'd store the cart in a secondary cookie that is dedicated to the cart, and nothing else. The problem with CI's cookie based session is that it is potentially serializing and encrypting a lot of unrelated data. You can easily run out of space. Using the database is another option, but then you are adding one more query for every pageload, which I think is a waste of a query. If CI was really smart, it would create more cookies to handle the session when the first is too full.

Skunkbad, you are right. The issue was being caused because of the cookie size limit. For now, I have switched to storing sessions in DBs but I am not too excited about the additional DB query.

Can you elaborate on the secondary cookie for cart? How can I do that while still using the Cart library?

You would need to extend the cart class to use regular cookies instead of the CI session. Basically, anytime the cookie is created, updated, etc, then you change the code to use a regular cookie. Have you ever extended a class before?

Theme © iAndrew 2016 - Forum software by © MyBB