Basket for code generators: adding the same product again

This is my first time browsing the CodeIgniter basket library. I have all the settings for my session, and when I go to add an item to the cart, it appears in $ this-> cart-> contents (); So far, so good. The addition is as follows:

$data = array( 'id' => 1, 'qty' => 1, 'price' => 20, 'name' => "Item1"); $rowid = $this->cart->insert($data); 

But when I try to add the same element again, it does not increase the amount of this element in the basket. I imagined that doing the same insert would add another one, increasing the number of this line to 2, but it is not.

If I add another product, it appears next to the first. But again, attempts to add another one of this product do not allow to increase the score.

Of course, I don’t notice something. Perhaps you know what it is.

Thank you very much!

+4
source share
2 answers

I believe that simply adding two elements does not sum them together to get a new quantity.

In fact, you can update the cart with the new quantity value [qty]. See the “Recycle Bin Update” section on this page: http://codeigniter.com/user_guide/libraries/cart.html

Note. You will probably need to do the following:

  • Get product information using $this->cart->product_options($rowid); or by scrolling through all the elements and finding the correct one using $this->cart->contents();
  • Get the amount from this array
  • Increase in quantity by one
  • Update $rowid with a new quantity value

Hope this helps!

+4
source

I needed something like this in my application some time ago, so I edited some of the CI cart features. Take a look at this topic.

Codeigniter Shopping Basket

I hope you can use some kind of code from it, at least it will point you in the right direction.

+1
source

All Articles