laravelshoppingcart icon indicating copy to clipboard operation
laravelshoppingcart copied to clipboard

more than 1 item not added to cart

Open avigato opened this issue 7 years ago • 6 comments

Hi, I'm using laravel 5.5 with darryldecode/cart 3.0.

addToCart function in Controller: ` if(Cart::session($userid)->get($itemid)){ Cart::session($userid)->update($itemid, array('quantity' => $quantity));
}else{ Cart::session($userid)->add(array( 'id' => $vino->articolo, 'name' => $vino->descrizione, 'price' => $vino->prezzo_vendita, 'quantity' => $quantity, //'attributes' => array(), )); }

$cart = Cart::session($userid)->getContent();
$cart['total'] = Cart::session($userid)->getTotal();

`

I'm using the userID for the user and the item ID (SKU) as rowID. The first item added to the session is working good, if I try to update the quantity by the rowID is ok. But whatever I add after the first item is not being added to the session and not recognized anymore by the update code.

So I end with something like this:

{"SCR06":{"id":"SCR06","name":"Amarone Classico della Valpolicella DOCG Magnum","price":68.5,"quantity":10,"attributes":[],"conditions":[]},"CCE10":{"id":"CCE10","name":"Cabernet Sauvignon Palazzo del Principe","price":8.9,"quantity":1,"attributes":[],"conditions":[]},"total":693.9}

The first item added, SRC06, is being updated correctly...the second one is not really registered in the session and I'm not able to update it. If I refresh and try $cart = Cart::session($userid)->getContent(); without the add, the first item appears correctly, the second one no.

How can I manage multiple item in the same session cart?

avigato avatar Apr 15 '18 02:04 avigato

I've managed to partially fix by disabling "encrypt cookie" and "http only" in session.php. There seems to be some problems with session and cache management but still can't understand why.

Now I can reach 3 items in cart, after the 3rd nothing is added to the session. Everything else is working good, I can get the total amount, total quantity and else but cannot add more than 3 items in the Cart.

avigato avatar Apr 18 '18 12:04 avigato

@Murphz hello, dude. Did you fix it? Have the same problem.

NurOleg avatar Dec 21 '18 13:12 NurOleg

@NurOleg can't remember the real fix. It was a problem with Laravel sessions anyway, after using database and fixing something in a file of the package, everything was ok.

avigato avatar Dec 22 '18 15:12 avigato

Could be nice to know the fix, as this package is bugged, maybe you could do a pull request.

tripex avatar Dec 28 '18 22:12 tripex

what was the solution??

ic-armando-1992 avatar Feb 26 '20 08:02 ic-armando-1992

I solved this by changing SESSION DRIVER from cookies to file in .env file

BilalYameen avatar Mar 25 '20 22:03 BilalYameen