darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.33k stars 436 forks source link

more than 1 item not added to cart #131

Open avigato opened 6 years ago

avigato commented 6 years ago

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 commented 6 years ago

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.

NurOleg commented 5 years ago

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

avigato commented 5 years ago

@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.

tripex commented 5 years ago

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

ic-armando-1992 commented 4 years ago

what was the solution??

BilalYameen commented 4 years ago

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